glimr/routing/router
Router
Pattern matching router with prefix-based route groups for organizing routes with shared middleware. Provides type-safe parameter extraction and lazy loading of route handlers based on URL prefix matching.
Types
Groups routes together with a shared middleware group and handler function. Routes use pattern matching for type-safe parameter extraction. The prefix field enables efficient route matching and lazy loading of route modules.
pub type RouteGroup(context) {
RouteGroup(
prefix: String,
middleware_group: kernel.MiddlewareGroup,
routes: fn(
List(String),
http.Method,
request.Request(wisp.Connection),
context,
) -> response.Response(wisp.Body),
)
}
Constructors
-
RouteGroup( prefix: String, middleware_group: kernel.MiddlewareGroup, routes: fn( List(String), http.Method, request.Request(wisp.Connection), context, ) -> response.Response(wisp.Body), )
Values
pub fn handle(
req: request.Request(wisp.Connection),
ctx: ctx,
route_groups: List(RouteGroup(ctx)),
kernel_handle: fn(
request.Request(wisp.Connection),
ctx,
kernel.MiddlewareGroup,
fn(request.Request(wisp.Connection)) -> response.Response(
wisp.Body,
),
) -> response.Response(wisp.Body),
) -> response.Response(wisp.Body)
Main entry point for routing HTTP requests. Matches the request path against registered route groups, strips the prefix, applies middleware, and calls the route handler.
Route groups are checked in order. The first matching prefix wins. Empty prefix (“”) acts as a catch-all and should always be last in your route group list.
Flow for GET /api/users/123:
- Parse path into [“api”, “users”, “123”]
- Find group with prefix “/api”
- Strip prefix → [“users”, “123”]
- Apply API middleware group
- Call routes([“users”, “123”], Get, req, ctx)