Struct radix_router::router::Router[][src]

pub struct Router<T> {
    pub trees: BTreeMap<String, Node<T>>,
    pub redirect_trailing_slash: bool,
    pub redirect_fixed_path: bool,
    pub handle_method_not_allowed: bool,
    pub handle_options: bool,
    pub not_found: Option<T>,
    pub method_not_allowed: Option<T>,
    pub panic_handler: Option<T>,
}

Router is container which can be used to dispatch requests to different handler functions via configurable routes

Fields

Methods

impl<T> Router<T>
[src]

New returns a new initialized Router. Path auto-correction, including trailing slashes, is enabled by default.

get is a shortcut for router.handle("GET", path, handle)

head is a shortcut for router.handle("HEAD", path, handle)

options is a shortcut for router.handle("OPTIONS", path, handle)

post is a shortcut for router.handle("POST", path, handle)

put is a shortcut for router.handle("PUT", path, handle)

patch is a shortcut for router.handle("PATCH", path, handle)

delete is a shortcut for router.handle("DELETE", path, handle)

Unimplemented. Perhaps something like

Example

This example is not tested
router.group(vec![middelware], |router| {
    router.get("/something", somewhere);
    router.post("/something", somewhere);
})

Handle registers a new request handle with the given path and method.

For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.

This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).

Lookup allows the manual lookup of a method + path combo.

This is e.g. useful to build a framework around this router.

If the path was found, it returns the handle function and the path parameter values. Otherwise the third return value indicates whether a redirection to the same path with an extra / without the trailing slash should be performed.

impl Router<Handler>
[src]

ServeFiles serves files from the given file system root.

The path must end with "/*filepath", files are then served from the local path /defined/root/dir/*filepath.

For example if root is "/etc" and *filepath is "passwd", the local file "/etc/passwd" would be served.

extern crate radix_router;
use radix_router::router::{Router, Handler};
let mut router: Router<Handler> = Router::new();
router.serve_files("/examples/*filepath", "examples");

Trait Implementations

impl Service for Router<Handler>
[src]

Service makes the router capable for Hyper.

The Payload body of the http::Request.

The Payload body of the http::Response.

The error type that can occur within this Service. Read more

The Future returned by this Service.

call makes the router implement the Service trait.

impl IntoFuture for Router<Handler>
[src]

The future that this type can be converted into.

The item that the future may resolve with.

The error that the future may resolve with.

Consumes this object and produces a future.

Auto Trait Implementations

impl<T> Send for Router<T> where
    T: Send

impl<T> Sync for Router<T> where
    T: Sync