Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetQueryParams does not support "Multi" inputs #28

Closed
guohuang opened this issue May 6, 2016 · 13 comments
Closed

SetQueryParams does not support "Multi" inputs #28

guohuang opened this issue May 6, 2016 · 13 comments
Assignees

Comments

@guohuang
Copy link

guohuang commented May 6, 2016

Does Resty support Multiple params? I am passing any array of statuses for query param, i am expecting the querystring is
?status=pending&status=approved, but what i got from the debugger is only appending the first value,(status=pending)
here is my code

    var status = []string {"pending","approved"}
    for _, value := range status {
        resty.R().SetQueryParam("status",value)
    }

fyi, i also tried SetQueryParams, but since it is a dictionary, you can't have multiple values, so it won't work either. I know the work around is converting status array to a comma separated strings, but I prefer to set multiple parameters.

are you going to add this feature in the near future?

cc @wing328

@jeevatkm jeevatkm self-assigned this May 6, 2016
@jeevatkm
Copy link
Member

jeevatkm commented May 6, 2016

Just had a look. It seem these two lines L50 and L53 requires change from method Set to method Add.

Would like to you send PR or I can do it over weekend?

@jeevatkm jeevatkm added this to the v0.8 Milestone milestone May 6, 2016
@guohuang
Copy link
Author

guohuang commented May 6, 2016

I tried it, it didn't work, i looked further in net/url package, it is also a dictionary, so either way it will not work.


// Set sets the key to value. It replaces any existing
// values.
func (v Values) Set(key, value string) {
    v[key] = []string{value}
}

// Add adds the value to key. It appends to any existing
// values associated with key.
func (v Values) Add(key, value string) {
    v[key] = append(v[key], value)
}

@guohuang
Copy link
Author

guohuang commented May 6, 2016

see this, https://golang.org/pkg/net/url/

func (Values) Add

func (v Values) Add(key, value string)
Add adds the value to key. It appends to any existing values associated with key.

@jeevatkm
Copy link
Member

jeevatkm commented May 6, 2016

Update:
@guohuang I will add this support by today and let you know.

You're correct. Yes query param name is unique in the URI, as per URI RFC.

So as per RFC, you can get multi-value after changing those two lines I mentioned above.

for e.g.: ?status=pending&status=approved

@jeevatkm
Copy link
Member

jeevatkm commented May 6, 2016

@guohuang I have updated the comment.

@guohuang
Copy link
Author

guohuang commented May 6, 2016

yes, we can always use ?status=pending,approved as work around, but we want ?status=pending&status=approved, looking at https://github.com/go-resty/resty/blob/master/request.go#L91, your proposed solution doesn't work, as QueryParam is a dictionary.

@jeevatkm
Copy link
Member

jeevatkm commented May 6, 2016

I will add this support, also I have updated the previous comment. Once done I will update this issue.

@jeevatkm
Copy link
Member

jeevatkm commented May 7, 2016

I have added the support. It's available on master. Give it a try and let me know.

@guohuang
Copy link
Author

guohuang commented May 7, 2016

yup, it works! thanks for the quick fix!

@jeevatkm
Copy link
Member

jeevatkm commented May 7, 2016

Nice. I'm closing this one.

@jeevatkm jeevatkm closed this as completed May 7, 2016
@jeevatkm
Copy link
Member

jeevatkm commented May 7, 2016

BTW, I have added this new method SetMultiValueQueryParams.

@guohuang
Copy link
Author

guohuang commented May 7, 2016

Nice! you are really quick and professional!

@jvitoroc
Copy link

Has the function name changed overtime? It seems it is "SetQueryParamsFromValues" now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants