fist
Types
Metadata about a registered route, introspectable via fist.inspect.
pub type RouteInfo =
@internal RouteInfo
Values
pub fn allowed_methods(
router: Router(req_body, ctx, output),
path: String,
) -> List(http.Method)
Returns a list of all HTTP methods supported for the given path. Useful for handling CORS preflight OPTIONS requests and 405 Method Not Allowed responses.
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)
Attaches a human-readable description to the last added route.
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. Middlewares are applied in declaration order: the first middleware in the list executes first, wrapping subsequent middlewares and handlers.
pub fn handle(
router: Router(req_body, ctx, output),
request: request.Request(req_body),
context: ctx,
not_found: fn() -> output,
) -> output
Dispatches an incoming request through the router.
If no route matches, the not_found fallback function is invoked.
pub fn head(
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 HEAD route to the router.
pub fn inspect(
router: Router(req_body, ctx, output),
) -> List(RouteInfo)
Returns a list of all registered routes and their metadata.
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 merge(
a: Router(req, ctx, out),
b: Router(req, ctx, out),
) -> Router(req, ctx, out)
Merges two routers with identical context and output types into a single combined router. Route trees are merged recursively. Collisions in routes or dynamic parameter names cause an immediate fail-fast panic.
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 options(
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 an OPTIONS route to the 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)
Adds a route for an arbitrary HTTP method and path to the router.
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.