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

How can I receive multiple parameters in GET request? #338

Open
k0fi opened this issue Sep 14, 2021 · 3 comments
Open

How can I receive multiple parameters in GET request? #338

k0fi opened this issue Sep 14, 2021 · 3 comments

Comments

@k0fi
Copy link

k0fi commented Sep 14, 2021

I'd like to handle an HTTP GET request, like this:

/search/projects?page=0&min=0&max=10000&ids=57,28,55,53,51,611,619,610,578,96,4,177

As far as I see in the docs only one parameter is mentioned in get requests. So I'm wondering how can I achieve a multi-parameter GET?

@dbubel
Copy link
Contributor

dbubel commented Nov 20, 2021

You should be able to get the query params like this off your request r.

min := r.URL.Query().Get("min")
max := r.URL.Query().Get("max")

I think what you are asking about is httprouter.Params. Say you have this route /api/users/:userId you could access userId in your handler as shown below.

func users(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
 userId: = p.ByName("userid")
}

@go-aegian
Copy link

I made some changes to the project but waiting on approval to get them merged, in the meantime what you are asking can be done check it out here https://github.com/sainzg/httprouter/blob/main/params_test.go - TestMissingContextParams

@letmestudy
Copy link

letmestudy commented Dec 10, 2021 via email

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

No branches or pull requests

4 participants