glitr_wisp

Types

A Router is basically a request handler for glitr Routes
It store the incoming request and will compare it to the different Routes that are provided to it. The resulting response is generated based on the matching Route and the handler associated to it.

pub opaque type Router

Functions

pub fn for(
  req: Request(Connection),
) -> Result(Router, Response(Body))

Create a new Router for the incoming request

pub fn try(
  router_res: Result(Router, Response(Body)),
  route: Route(a, b, c, d),
  handler: fn(RouteOptions(a, b, c)) -> Result(d, AppError),
) -> Result(Router, Response(Body))

Compare the stored request with the provided Route
If the first parameter has a response, this will be ignored. Otherwise, if the request match the Route, generate a response based on the provided handler, else return the Router so that these functions can be chained.

pub fn try_map(
  router_res: Result(Router, Response(Body)),
  route: Route(a, b, c, d),
  handler: fn(RouteOptions(a, b, c)) -> Result(d, AppError),
  map_fn: fn(Response(Body)) -> Response(Body),
) -> Result(Router, Response(Body))

Do the same as the try function but also map the generated response

pub fn unwrap(
  router_res: Result(Router, Response(Body)),
) -> Response(Body)

Unwrap the response generated by a Route or return a not_found if no route matched

Search Document