httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

How can I receive multiple parameters in GET request?

Open k0fi opened this issue 3 years ago • 3 comments

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?

k0fi avatar Sep 14 '21 17:09 k0fi

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")
}

dbubel avatar Nov 20 '21 03:11 dbubel

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

go-aegian avatar Dec 10 '21 20:12 go-aegian

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

letmestudy avatar Dec 10 '21 20:12 letmestudy