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
-
Route( handler: fn( request.Request(req_body), ctx, dict.Dict(String, String), ) -> output, description: option.Option(String), )
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), )
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 group(
router: Router(req, ctx, out),
at prefix: String,
with middlewares: List(
fn(
fn(request.Request(req), ctx, dict.Dict(String, String)) -> out,
) -> fn(request.Request(req), ctx, dict.Dict(String, String)) -> out,
),
defining build_sub_router: fn(Router(req, ctx, out)) -> Router(
req,
ctx,
out,
),
) -> Router(req, ctx, out)
Groups a set of routes under a common prefix and applies middlewares. Middleware is applied at definition time (Static Wrapping).
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 map_context(
router: Router(req_body, ctx_b, output),
with mapper: fn(ctx_a) -> ctx_b,
) -> Router(req_body, ctx_a, output)
Transforms the context of the router using a mapping function. This is the foundation for context polymorphism, allowing a sub-router that expects a specific context to be used within a parent router with a different context.
pub fn mount(
parent: Router(req, ctx_a, out),
at prefix: String,
sub sub_router: Router(req, ctx_b, out),
transform mapper: fn(ctx_a) -> ctx_b,
) -> Router(req, ctx_a, out)
Mounts a sub-router at a specific prefix, transforming its context to match the parent. This enables modular routing and context polymorphism.
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.
pub fn wrap(
router: Router(req, ctx, out),
with middleware: fn(
fn(request.Request(req), ctx, dict.Dict(String, String)) -> out,
) -> fn(request.Request(req), ctx, dict.Dict(String, String)) -> out,
) -> Router(req, ctx, out)
Wraps all handlers in the router with the given middleware. A middleware is a function that takes a handler and returns a new, wrapped handler.