February 2020
Intermediate to advanced
404 pages
8h 42m
English
Query parameters are variables that get passed along with the URL in an HTTP request. This is what we commonly see in a REST GET request. The gorilla/mux route can match and collect query parameters. See this following URL, for example:
http://localhost:8000/articles?id=123&category=books
It has id and category as query parameters. All query parameters begin after the ? character.
Let us modify our copy of our previous example into a new one with the name queryParameters/main.go. Modify the route object to point to a new handler called QueryHandler, like this:
// Add this in your main programr := mux.NewRouter()r.HandleFunc("/articles", QueryHandler)
In QueryHandler, we can use request.URL.Query() to obtain query parameters ...
Read now
Unlock full access