fist

Types

A node in the router tree, representing a route segment.

pub type Node(req_body, ctx, output) {
  Node(
    handler: option.Option(
      fn(
        request.Request(req_body),
        ctx,
        dict.Dict(String, String),
      ) -> output,
    ),
    static_children: dict.Dict(
      String,
      Node(req_body, ctx, output),
    ),
    dynamic_child: option.Option(
      #(String, Node(req_body, ctx, output)),
    ),
  )
}

Constructors

A router that handles HTTP requests by matching routes and executing handlers.

pub opaque type Router(req_body, ctx, output)

Values

pub fn delete(
  router: Router(req_body, ctx, output),
  path path: String,
  to handler: fn(
    request.Request(req_body),
    ctx,
    dict.Dict(String, String),
  ) -> output,
) -> Router(req_body, ctx, output)

Adds a DELETE route to the router.

pub fn get(
  router: Router(req_body, ctx, output),
  path path: String,
  to handler: fn(
    request.Request(req_body),
    ctx,
    dict.Dict(String, String),
  ) -> output,
) -> Router(req_body, ctx, output)

Adds a GET route to the router.

pub fn handle(
  router: Router(req_body, ctx, output),
  request: request.Request(req_body),
  context: ctx,
  not_found: fn() -> output,
) -> output

define a route handler for a given method and path

pub fn map(
  router: Router(req_body, ctx, a),
  with fun: fn(a) -> b,
) -> Router(req_body, ctx, b)

Maps the output of all handlers in the router.

pub fn new() -> Router(req_body, ctx, output)

Creates a new empty router.

pub fn patch(
  router: Router(req_body, ctx, output),
  path path: String,
  to handler: fn(
    request.Request(req_body),
    ctx,
    dict.Dict(String, String),
  ) -> output,
) -> Router(req_body, ctx, output)

Adds a PATCH route to the router.

pub fn post(
  router: Router(req_body, ctx, output),
  path path: String,
  to handler: fn(
    request.Request(req_body),
    ctx,
    dict.Dict(String, String),
  ) -> output,
) -> Router(req_body, ctx, output)

Adds a POST route to the router.

pub fn put(
  router: Router(req_body, ctx, output),
  path path: String,
  to handler: fn(
    request.Request(req_body),
    ctx,
    dict.Dict(String, String),
  ) -> output,
) -> Router(req_body, ctx, output)

Adds a PUT route to the router.

pub fn route(
  router: Router(req_body, ctx, output),
  method method: http.Method,
  path path: String,
  handler handler: fn(
    request.Request(req_body),
    ctx,
    dict.Dict(String, String),
  ) -> output,
) -> Router(req_body, ctx, output)

Inserts a route into the router.

Search Document