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
-
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)), ), )
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
pub fn json(body: String) -> response.Response(String)
Creates a 200 OK response with the given string as body and application/json content type.
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 ok(body: body) -> response.Response(body)
Creates a 200 OK response with the given body.
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 redirect(to: String) -> response.Response(String)
Creates a 302 Found redirect response.
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.
pub fn text(body: String) -> response.Response(String)
Creates a 200 OK response with the given string as body and text/plain content type.