fist

Types

A node in the router’s internal Trie structure.

pub type Node(req_body, ctx, output) {
  Node(
    route: option.Option(Route(req_body, ctx, output)),
    static_children: dict.Dict(
      String,
      Node(req_body, ctx, output),
    ),
    dynamic_child: option.Option(
      #(String, Node(req_body, ctx, output)),
    ),
  )
}

Constructors

  • Node(
      route: option.Option(Route(req_body, ctx, output)),
      static_children: dict.Dict(String, Node(req_body, ctx, output)),
      dynamic_child: option.Option(
        #(String, Node(req_body, ctx, output)),
      ),
    )

    Arguments

    route

    If this node represents the end of a valid path, it will have a Route object.

    static_children

    Static children are exact string matches (e.g., “users”, “settings”).

    dynamic_child

    A dynamic child is a wildcard parameter (e.g., “:id”, “:slug”).

Encapsulates the handler logic and its metadata.

pub type Route(req_body, ctx, output) {
  Route(
    handler: fn(
      request.Request(req_body),
      ctx,
      dict.Dict(String, String),
    ) -> output,
    description: option.Option(String),
  )
}

Constructors

Information about a registered route, used for introspection/documentation.

pub type RouteInfo {
  RouteInfo(
    method: http.Method,
    path: String,
    description: String,
    params: List(String),
  )
}

Constructors

  • RouteInfo(
      method: http.Method,
      path: String,
      description: String,
      params: List(String),
    )

The main Router type.

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 describe(
  router: Router(req_body, ctx, output),
  description: String,
) -> Router(req_body, ctx, output)

Adds a description to the last added route. This enables the chaining syntax: |> fist.get(...) |> fist.describe("...")

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
pub fn inspect(
  router: Router(req_body, ctx, output),
) -> List(RouteInfo)

Returns a list of all registered routes with their metadata. Useful for generating documentation (OpenAPI) or debugging.

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

Transforms the output of the router using a mapping function.

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)

Generic function to add a route for a specific method.

Search Document