reroute
A router for Rust's hyper framework using regular expressions.
Documentation
Documentation is here
A simple example to demonstrate how to use the router:
extern crate hyper;
extern crate reroute;
use hyper::Server;
use hyper::server::{Request, Response};
use reroute::{Captures, Router};
fn digit_handler(_: Request, res: Response, c: Captures) {
println!("captures: {:?}", c);
res.send(b"It works for digits!").unwrap();
}
fn main() {
let mut router = Router::new();
router.get(r"/(\d+)", digit_handler);
router.finalize().unwrap();
Server::http("127.0.0.1:3000").unwrap().handle(router).unwrap();
}
You can then hit localhost on port 3000 to see the responses based on the routes
that you pass.
curl localhost:3000/123 ->
captures: Some(["/123", "123"])
It works for digits!
curl localhost:3000/faux ->
No route found for /faux