Rust

router

Module

The routing table: routes by HTTP method and path template, matched against request paths.

A path /users/:id is stored as the template users/::: with the param id at segment 1. Matching tries the request's segments with placeholders substituted at every combination of param positions, deepest positions first, so a static segment wins over a placeholder at the leftmost position where two templates differ. A route can be registered under several methods and alias paths; * templates match a path prefix; a method-agnostic wildcard catches everything else.

Contents

use utopia_http::Match;
Rust
pub struct Match<'a, T>

A matched route and its path params.

use utopia_http::Router;
Rust
pub struct Router<T>

The routing table: values of type T (an application stores Routes) by method and path template, each with a stable id.

Also implements Default.
Rust
pub type PathParams = Vec<(String, String)>

Path params parsed from a request path, by name.

Rust
pub const METHODS: [&str; 5] = ["GET", "POST", "PUT", "PATCH", "DELETE"]

The methods a route can be registered under.

Rust
pub const PLACEHOLDER: &str = ":::"

The segment that stands for a param in a stored template.

Rust
pub const WILDCARD: &str = "*"

The path segment that matches any path suffix (/assets/*) or, alone, any path.