March Docs

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

fnauthorizationauthorization(conn : Conn) : Option(String)#

Returns the Authorization header value, if present.

fnbodybody(conn : Conn) : String#

Returns the raw request body string.

fnbody_paramsbody_params(conn : Conn) : List((String, 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")]
fncontent_typecontent_type(conn : Conn) : Option(String)#

Returns the Content-Type request header value, if present.

fnget_assignget_assign(conn : Conn, key : String) : Option(String)#

Look up a value stored in conn assigns by key.

fnget_headerget_header(conn : Conn, name : String) : Option(String)#

Look up a request header by name (case-insensitive).

fnget_path_paramget_path_param(conn : Conn, name : String) : Option(String)#

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")
fnget_query_paramget_query_param(conn : Conn, key : String) : Option(String)#

Look up a single query parameter by name. Returns None if absent.

fnjson_bodyjson_body(conn : Conn) : Result(JsonValue, String)#

Parse the request body as JSON. Returns Ok or Err.

fnpath_parampath_param(conn : Conn, name : String) : Option(String)#

Alias for get_path_param. Returns the named path parameter captured by the router.

fnquery_paramsquery_params(conn : Conn) : List((String, String))#

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")]
fnuser_agentuser_agent(conn : Conn) : Option(String)#

Returns the User-Agent header value, if present.