glimr/routing/router


Route Matcher

Route matching engine that finds and executes matching routes from registered route groups. Handles URL parameter extraction, middleware application, and route resolution.

Values

pub fn apply_middleware(
  route_req: route.RouteRequest,
  ctx: context,
  middleware: List(
    fn(
      request.Request(wisp.Connection),
      context,
      fn(request.Request(wisp.Connection)) -> response.Response(
        wisp.Body,
      ),
    ) -> response.Response(wisp.Body),
  ),
  handler: fn(route.RouteRequest, context) -> response.Response(
    wisp.Body,
  ),
) -> response.Response(wisp.Body)

Apply Route Middleware

Recursively applies middleware to a request in order. The first middleware in the list wraps all others, so it has the final say on the response. Middleware execute in order going in, and reverse order coming out.

pub fn find_matching_route_in_groups(
  route_groups: List(route.RouteGroup(context)),
  path: String,
  method: http.Method,
) -> Result(
  #(
    route.Route(context),
    dict.Dict(String, String),
    kernel.MiddlewareGroup,
  ),
  Nil,
)

Find Matching Route in Groups

Searches through route groups to find a route matching the given path and HTTP method. Returns the matched route, and extracted URL parameters, and the middleware group. Returns Error if no match is found.

pub fn get_all_routes(
  route_groups: List(route.RouteGroup(context)),
) -> List(route.Route(context))

Get All Routes

Extracts all routes from all route groups into a single flat list. Useful for debugging, route listing, or determining if a path exists (for 404 vs 405 status codes).

pub fn matches_path(pattern: String, path: String) -> Bool

Check Path Match

Tests if a URL path matches a route pattern. This Supports dynamic parameters like /users/{id}. Compares segment by segment, treating parameters as wildcards that match a value

Search Document