Struct reroute::Router [] [src]

pub struct Router {
    pub not_found: Option<NotFoundFn>,
    // some fields omitted
}

The Router struct contains the information for your app to route requests properly based on their HTTP method and matching route. It allows the use of a custom 404 handler if desired but provides a default as well.

Under the hood a Router uses a RegexSet to match URI's that come in to the instance of the hyper server. Because of this, it has the potential to match multiple patterns that you provide. It will call the first handler that it matches against so the order in which you add routes matters.

Fields

not_found: Option<NotFoundFn>

A custom 404 handler that you can provide.

Methods

impl Router
[src]

fn new() -> Router

Construct a new Router to maintain the routes and their handler functions.

fn add_route<H>(&mut self, verb: Method, route: &str, handler: H) where H: Fn(Request, Response, Captures) + Send + Sync + 'static

Add a route to the router and give it a function to call when the route is matched against. You can call this explicitly or use the convenience methods defined below.

fn options<H>(&mut self, route: &str, handler: H) where H: Fn(Request, Response, Captures) + Send + Sync + 'static

A convenience method for OPTIONS requests.

fn get<H>(&mut self, route: &str, handler: H) where H: Fn(Request, Response, Captures) + Send + Sync + 'static

A convenience method for GET requests.

fn post<H>(&mut self, route: &str, handler: H) where H: Fn(Request, Response, Captures) + Send + Sync + 'static

A convenience method for POST requests.

fn put<H>(&mut self, route: &str, handler: H) where H: Fn(Request, Response, Captures) + Send + Sync + 'static

A convenience method for PUT requests.

fn delete<H>(&mut self, route: &str, handler: H) where H: Fn(Request, Response, Captures) + Send + Sync + 'static

A convenience method for DELETE requests.

fn finalize(&mut self) -> Result<(), RouterError>

This function ensures that a valid RegexSet could be made from the route vector that was built while using the functions that add routes. It requires that there exist at least one route so that the RegexSet can be successfully constructed.

It will also ensure that there is a handler for routes that do not match any available in the set.

fn add_not_found(&mut self, not_found: NotFoundFn)

Add a function to handle routes that get no matches.

Trait Implementations

impl Send for Router
[src]

impl Sync for Router
[src]

impl Handler for Router
[src]

fn handle(&self, req: Request, res: Response)

Receives a Request/Response pair, and should perform some action on them. Read more

fn check_continue(&self, (&Method, &RequestUri, &Headers)) -> StatusCode

Called when a Request includes a Expect: 100-continue header. Read more

fn on_connection_start(&self)

This is run after a connection is received, on a per-connection basis (not a per-request basis, as a connection with keep-alive may handle multiple requests) Read more

fn on_connection_end(&self)

This is run before a connection is closed, on a per-connection basis (not a per-request basis, as a connection with keep-alive may handle multiple requests) Read more