/router

Router middleware for the Iron web framework.

Primary LanguageRust

router Build Status

Routing middleware for the Iron web framework.

Router is a fast, convenient, and flexible routing middleware for Iron. It allows complex glob patterns and named url parameters and also allows handlers to be any Middleware - including Chain, which provides enormous amounts of flexibility for handling and dispatching requests.

Example

fn main() {
    let mut router = Router::new();
    router.route( // Setup our route.
        Get,
        "/:class/:id".to_string(),
        vec!["class".to_string(), "id".to_string()],
        echo_to_term);

    let mut server: Server = Iron::new();
    server.chain.link(router); // Add middleware to the server's stack
    server.listen(::std::io::net::ip::Ipv4Addr(127, 0, 0, 1), 3000);
}

fn echo_to_term(_: &mut Request, res: &mut Response, alloy: &mut Alloy) {
    let query = alloy.find::<Params>().unwrap();
    println!("Class: {}\t id: {}",
             query.get("class").unwrap(), query.get("id").unwrap());
}

Overview

router is a part of Iron's core bundle.

  • Route client requests based on their paths
  • Parse parameters and provide them to other middleware/handlers

Installation

If you're using a Cargo.toml to manage dependencies, just add router to the toml:

[dependencies.router]

git = "https://github.com/iron/router.git"

Otherwise, cargo build, and the rlib will be in your target directory.

Along with the online documentation, you can build a local copy with make doc.

Get Help

One of us (@reem, @zzmp, @theptrk, @mcreinhard) is usually on #iron on the mozilla irc. Come say hi and ask any questions you might have. We are also usually on #rust and #rust-webdev.