liveBook · Manning

Parameter

As explained in Learn Go with Pocket-Sized Projects

A query parameter is an optional key-value component of a URL that supplies filtering or other request options to an API.

A query parameter supplies an optional key-value input to an HTTP request. It follows the path after `?`; separate multiple `key=value` pairs with `&`. For example, `?lang=en` supplies the key `lang` with the value `en`. Query parameters can filter resources or provide other request options. section 8.6.5 section 8.2.2

Choose a path parameter when the URL must identify one resource, such as `/games/{gameID}`. Choose a query parameter for an optional choice, such as the language of a new game. Unlike the resource identifier in the path, the query choice need not be present. section 8.2.2 section 8.6.5

Read a language option in Go

For `http://localhost:8080/game?lang=en`, define `Lang = "lang"` and read `lang := r.URL.Query().Get(api.Lang)` in the handler. Check `len(lang) > 0` before using it. The shown handler prints the value; creating a game in that language remains a TODO. section 8.6.5

The same pattern can make week navigation optional: read `r.URL.Query().Get("week")` and default to `time.Now()` when it is absent. If a URL can request a future week, check the value in the handler rather than relying on a hidden navigation link. section 11.5.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains query-string syntax and shows Go handler retrieval; leaves creation in the selected language unimplemented.
Examples
Uses `?lang=en` for game creation and proposes `?week=` for previous or next week navigation.
What it assumes
Assumes familiarity with Go HTTP handlers while teaching query-string syntax and retrieval explicitly.
What you can do after
Apply it via Go's `r.URL.Query().Get` to read an optional request value in a handler.
How it connects
Contrasts with path parameters and connects to HTTP handlers, URL query parsing, and request testing.

Also explained in

Compare how 31 books explain parameter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.