Context API to access every part of an incoming request. All methods live on the *Context value passed to your handler.
URL Parameters
Define dynamic segments in your route pattern with a: prefix. Read them at runtime with ctx.Param().
(T, error) so you can handle malformed values explicitly:
Use
ctx.Params() to get all URL parameters as map[string]string at once.
Query Parameters
Read query string values withctx.Query() for strings or the typed helpers for numeric and boolean values.
Use
ctx.Queries() to get all query parameters as map[string][]string.
Request Body
JSON body
Usectx.JSONBody(&v) to decode the request body into a struct. Pass true as the second argument to also validate the struct using go-playground/validator struct tags.
false) to skip validation and decode only:
Raw and string body
Headers
Read a single request header by name withctx.Header(). Header names are case-insensitive.
ctx.Headers() to get all request headers as map[string]string.
Cookies
Read a single cookie by name withctx.Cookie(). It returns *fasthttp.Cookie (or nil if the cookie is not present).
ctx.Cookies() to iterate over all cookies in the request:
Complete Example: POST Handler with JSON Validation
The following handler parses a JSON body, validates it, and returns a structured response.ctx.JSONBody returns the first validation error as a Go error, and ctx.Fail(-1, err.Error()) sends it back to the client.