Struct router::Router [] [src]

pub struct Router {
    // some fields omitted
}

Router provides an interface for creating complex routes as middleware for the Iron framework.

Methods

impl Router
[src]

fn new() -> Router

Construct a new, empty Router.

let router = Router::new();

fn route<H, S>(&mut self, method: Method, glob: S, handler: H) -> &mut Router where H: Handler, S: AsRef<str>

Add a new route to a Router, matching both a method and glob pattern.

route supports glob patterns: * for a single wildcard segment and :param for matching storing that segment of the request url in the Params object, which is stored in the request extensions.

For instance, to route Get requests on any route matching /users/:userid/:friend and store userid and friend in the exposed Params object:

let mut router = Router::new();
router.route(method::Get, "/users/:userid/:friendid", controller);

The controller provided to route can be any Handler, which allows extreme flexibility when handling routes. For instance, you could provide a Chain, a Handler, which contains an authorization middleware and a controller function, so that you can confirm that the request is authorized for this route before handling it.

fn get<H: Handler, S: AsRef<str>>(&mut self, glob: S, handler: H) -> &mut Router

Like route, but specialized to the Get method.

fn post<H: Handler, S: AsRef<str>>(&mut self, glob: S, handler: H) -> &mut Router

Like route, but specialized to the Post method.

fn put<H: Handler, S: AsRef<str>>(&mut self, glob: S, handler: H) -> &mut Router

Like route, but specialized to the Put method.

fn delete<H: Handler, S: AsRef<str>>(&mut self, glob: S, handler: H) -> &mut Router

Like route, but specialized to the Delete method.

fn head<H: Handler, S: AsRef<str>>(&mut self, glob: S, handler: H) -> &mut Router

Like route, but specialized to the Head method.

fn patch<H: Handler, S: AsRef<str>>(&mut self, glob: S, handler: H) -> &mut Router

Like route, but specialized to the Patch method.

fn options<H: Handler, S: AsRef<str>>(&mut self, glob: S, handler: H) -> &mut Router

Like route, but specialized to the Options method.

Trait Implementations

impl Key for Router
[src]

type Value = Params

The value type associated with this key type.

impl Handler for Router
[src]

fn handle(&self, req: &mut Request) -> IronResult<Response>

Produce a Response from a Request, with the possibility of error.