route-rs
This crate is my attempt at a safe helper for mapping URL routes to handlers for rust web applications.
There are several routing libraries already available, but all of the ones I have been able to find share a common problem: path patterns are defined as strings, and URL parameters get parsed out at runtime and stashed in some kind of Map
that handlers have to .get()
and .unwrap()
to access. I want to extract parameters without unwrapping, and I want rust's type system to ensure that I'm not making mistakes!
Setup
in Cargo.toml:
[]
= "0.2.0"
route
just exports a the macro route!
, so you need to #[macro use]
it:
extern crate route;
Usage
Suppose you have some HTTP request/response server setup like
// imaginary request/response structs provided by the framework:
type Response = String;
// application handlers that we need to route:
// Note that some handlers take extra parameters that we hope to fill from the path!
Then you could set up a routing handler like:
And you're set!
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;