Crate rust_easy_router[][src]

Rust Easy Router

Library to add "matched" routing to the Rust web framework Iron. This can be used to build REST APIs with relative ease, and high stability.

Example Code:

extern crate rust-easy-router;

use rust-easy-router::*;

fn test_handle(vars: HashMap<String, String>, body: &mut Body) -> IronResult<Response>
{
    let mut string = "Vars:".to_owned();

    for (x, y) in &vars {
        string.push_str(&format!("\n{} -> {}", x, y));
    }

    string.push_str("\n");

    /* Get Body */
    let mut buf: String = "".to_owned();
    let res = body.read_to_string(&mut buf);
    string.push_str(&buf[..]);

    Ok (
        Response::with((status::Ok, string))
    )

}

fn main()
{
    /* Creates new Router instance */
    let mut router = Router::new();

    /* Add routes */
    router.get("/get_image/:user/:album/:image", test_handle);

    /* Closure for Iron */
    let handle = move |_req: &mut Request| -> IronResult<Response> {
        return router.handle(_req);
    };

    /* Start server */
    let server = Iron::new(handle).http("localhost:3000").unwrap();
    println!("Server ready on port 3000.");

}

Structs

MatchableUrl
MatchableUrlResult
Router