Request
Bastion.Request — request inspection and parsing helpers.
Provides structured access to request data: query string parameters, headers, body content, and path parameters stored in assigns.
All functions are pure transformations on HttpServer.Conn values.
Functions
Returns the Authorization header value, if present.
Returns the raw request body string.
Parse the request body as URL-encoded form data (application/x-www-form-urlencoded). Returns a list of (key, value) pairs — the same format as query_params. Keys and values are URL-decoded ("+" becomes space, %XX percent-decoded).
Example:
-- POST body: "title=Hello&body=World"
Request.body_params(conn) -- => [("title","Hello"), ("body","World")]Returns the Content-Type request header value, if present.
Look up a value stored in conn assigns by key.
Look up a request header by name (case-insensitive).
Look up a path parameter captured by the router (e.g. ":id" in "/users/:id").
Path params are stored in conn assigns by the router.
Example:
-- Route: "/users/:id"
Request.get_path_param(conn, "id") -- => Some("42")Look up a single query parameter by name. Returns None if absent.
Parse the request body as JSON. Returns Ok or Err.
Alias for get_path_param. Returns the named path parameter captured by the router.
Parse the query string into a list of (key, value) pairs.
Keys and values are URL-decoded ("+" becomes space, %XX sequences are
percent-decoded). Returns an empty list if the query string is empty.
Example:
-- For request "GET /search?q=hello&page=1"
Request.query_params(conn)
-- => [("q", "hello"), ("page", "1")]Returns the User-Agent header value, if present.