radiant/request

Request accessors, context keys, and request errors.

Types

A typed key for the request context.

pub opaque type Key(a)

Errors returned by request and context accessors.

pub type RadiantError {
  MissingHeader(String)
  InvalidUtf8Body
  MissingPathParam(String)
  InvalidIntParam(String, String)
  MissingQuery(String)
  InvalidIntQuery(String, String)
  InvalidFloatQuery(String, String)
  InvalidBoolQuery(String, String)
  MalformedQuery(String)
  MissingContext(String)
}

Constructors

  • MissingHeader(String)
  • InvalidUtf8Body
  • MissingPathParam(String)
  • InvalidIntParam(String, String)
  • MissingQuery(String)
  • InvalidIntQuery(String, String)
  • InvalidFloatQuery(String, String)
  • InvalidBoolQuery(String, String)
  • MalformedQuery(String)
  • MissingContext(String)

Opaque request wrapper with the original request, path params, and typed context.

pub opaque type Req

Values

pub fn body(req: Req) -> BitArray

The raw request body.

pub fn from_request(request: request.Request(BitArray)) -> Req

Low-level helper used by radiant/router to wrap an HTTP request.

pub fn get_context(
  req: Req,
  k: Key(a),
) -> Result(a, RadiantError)

Retrieve a typed value from the request context.

pub fn header(
  req: Req,
  key: String,
) -> Result(String, RadiantError)

Get a request header by key.

pub fn headers(req: Req) -> List(#(String, String))

All request headers.

pub fn int_param(
  req: Req,
  name: String,
) -> Result(Int, RadiantError)

Extract a path parameter as Int.

pub fn key(name: String) -> Key(a)

Create a typed context key.

pub fn key_named(namespace: String, name: String) -> Key(a)

Create a typed context key with an explicit namespace.

pub fn method(req: Req) -> http.Method

The request HTTP method.

pub fn original(req: Req) -> request.Request(BitArray)

Access the underlying Request(BitArray).

pub fn queries(req: Req) -> List(#(String, String))

All query parameters.

pub fn query(
  req: Req,
  key: String,
) -> Result(String, RadiantError)

Get a single query parameter by key.

pub fn query_bool(
  req: Req,
  key: String,
) -> Result(Bool, RadiantError)

Get a query parameter parsed as Bool.

pub fn query_float(
  req: Req,
  key: String,
) -> Result(Float, RadiantError)

Get a query parameter parsed as Float.

pub fn query_int(
  req: Req,
  key: String,
) -> Result(Int, RadiantError)

Get a query parameter parsed as Int.

pub fn req_path(req: Req) -> String

The request path.

pub fn set_context(req: Req, k: Key(a), value: a) -> Req

Store a typed value in the request context.

pub fn str_param(
  req: Req,
  name: String,
) -> Result(String, RadiantError)

Extract a path parameter as String.

pub fn text_body(req: Req) -> Result(String, RadiantError)

The request body decoded as UTF-8 text.

pub fn with_method(req: Req, method: http.Method) -> Req

Low-level helper used by radiant/router for HEAD-to-GET dispatch.

pub fn with_params(
  req: Req,
  params: dict.Dict(String, String),
) -> Req

Low-level helper used by radiant/router to attach extracted path params.

Search Document