glimr/routing/router
Router
Web apps and API endpoints need different middleware — HTML error pages vs JSON responses, static file serving vs CORS headers. Route groups let you split routes by prefix (e.g. “/api” vs everything else) and wire each group to the right middleware stack automatically.
Types
Deprecated: use glimr/router.RouteGroup instead
Each group bundles a URL prefix, a middleware stack, and the compiled route handler for that section of the app. The prefix enables fast matching — “/api/users/123” checks if the path starts with “/api” before even looking at the route table, and lazily loads only the matching module.
pub type RouteGroup(context) {
RouteGroup(
prefix: String,
middleware_group: kernel.MiddlewareGroup,
routes: fn(List(String), http.Method, context) -> response.Response(
wisp.Body,
),
)
}
Constructors
-
RouteGroup( prefix: String, middleware_group: kernel.MiddlewareGroup, routes: fn(List(String), http.Method, context) -> response.Response( wisp.Body, ), )
Values
pub fn handle(
ctx: context.Context(app),
route_groups: List(RouteGroup(context.Context(app))),
kernel_handle: fn(
context.Context(app),
kernel.MiddlewareGroup,
fn(context.Context(app)) -> response.Response(wisp.Body),
) -> response.Response(wisp.Body),
) -> response.Response(wisp.Body)
Deprecated: use glimr/router.handle instead
The main request entry point. Splits the URL into segments, finds the first route group whose prefix matches, applies that group’s middleware, and calls its route handler. Groups are checked in order — put specific prefixes like “/api” before the catch-all “” so they get a chance to match.
pub fn load(
routes_for: fn(String) -> fn(List(String), http.Method, context) -> response.Response(
wisp.Body,
),
) -> List(RouteGroup(context))
Deprecated: use glimr/router.load instead
Route groups are defined in config/route_group.toml so
adding a new API version or admin section is a config
change, not a code change. The routes_for callback maps
each group name to its compiled route handler so the router
knows which module handles which prefix.