Skip to content
forked from gsquire/reroute

A router for Rust's hyper framework using regular expressions

License

Notifications You must be signed in to change notification settings

team-worm/reroute

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reroute

Build Status

A router for Rust's hyper framework using regular expressions.

Documentation

Documentation is here

Examples

You can see the examples folder or check below.

A simple application to demonstrate how to use the router:

extern crate hyper;
extern crate reroute;

use hyper::Server;
use hyper::server::{Request, Response};
use reroute::{Captures, RouterBuilder};

fn digit_handler(_: Request, res: Response, c: Captures) {
    println!("captures: {:?}", c);
    res.send(b"It works for digits!").unwrap();
}

fn main() {
    let mut builder = RouterBuilder::new();

    // Use raw strings so you don't need to escape patterns.
    builder.get(r"/(\d+)", digit_handler);

    // There is no 404 handler added, so it will use the default defined in the
    // library.
    let router = builder.finalize().unwrap();

    // You can pass the router to hyper's Server's handle function as it
    // implements the Handle trait.
    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

About

A router for Rust's hyper framework using regular expressions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%