glimr/routing/route_group

Route Groups Configuration

A single monolithic route file becomes unwieldy as apps grow and different URL prefixes often need different middleware — API routes skip CSRF while web routes skip JSON parsing. Route groups let the compiler split routes by prefix into separate files, each wired to its own middleware stack at compile time so there’s zero runtime dispatch overhead for picking the right middleware.

Types

A typed struct so the route compiler can pattern match on the middleware variant at code generation time. The prefix determines which routes belong to this group, the name becomes the generated module name, and the middleware controls which kernel pipeline is wired in at compile time.

pub type RouteGroupConfig {
  RouteGroupConfig(
    name: String,
    prefix: String,
    middleware: kernel.MiddlewareGroup,
  )
}

Constructors

Values

pub fn load() -> List(RouteGroupConfig)

Called by the route compiler during code generation, so it must be fast on repeated calls. The persistent_term cache makes subsequent calls near-zero-cost. Returning an empty list on missing or invalid config lets the compiler fall back to a single default group — route grouping is optional.

Search Document