Skip to main content
Lightning gives you a clean 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().
Typed param helpers return (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 with ctx.Query() for strings or the typed helpers for numeric and boolean values.
All typed query helpers return zero values (not errors) when the key is absent, and return an error only when the value is present but cannot be parsed. Full set of typed query helpers: Use ctx.Queries() to get all query parameters as map[string][]string.

Request Body

JSON body

Use ctx.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.
Omit the second argument (or pass false) to skip validation and decode only:

Raw and string body

Headers

Read a single request header by name with ctx.Header(). Header names are case-insensitive.
Use ctx.Headers() to get all request headers as map[string]string.

Cookies

Read a single cookie by name with ctx.Cookie(). It returns *fasthttp.Cookie (or nil if the cookie is not present).
Use 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.
Example request:
Example response:
If validation fails, ctx.JSONBody returns the first validation error as a Go error, and ctx.Fail(-1, err.Error()) sends it back to the client.