Web Route
web-route provides an ergonomic way to define and manage web server routes in Rust.
Most web frameworks define routes using &str templates (e.g. "/foo/{param}"). This approach can become error-prone when you need to:
- Generate a callable version of a route (with parameters populated), for use in internal redirects, integration tests, etc.
- Join routes across nested routers — without having to worry about whether strings have leading/trailing slashes or resorting to
format!()gymnastics.
Features
- Cleanly define and join route segments
- Generate template routes for framework registration
- Generate populated routes with runtime parameters
- Slash handling is automatic and consistent
Usage
For complete examples, see the examples and integration tests.
use WebRoute;
// Define routes for parent and child routers
let parent_route = new;
let child_route = new;
// Join routes — no need to worry about trailing slashes
let full_route = parent_route.join;
// Convert to a route template (for use with frameworks like `axum`)
let template = parent_route.as_template_route;
assert_eq!;
// Generate a fully-populated route with parameter values
let populated = full_route
.as_populated_route
.unwrap;
assert_eq!;
Potential Improvements
- Enable compile-time validation of routes and parameters for even greater safety.