Struct radix_router::router::Router [−][src]
Router is container which can be used to dispatch requests to different handler functions via configurable routes
Fields
trees: BTreeMap<String, Node<T>>
Methods
impl<T> Router<T>
[src]
impl<T> Router<T>
pub fn new() -> Router<T>
[src]
pub fn new() -> Router<T>
New returns a new initialized Router. Path auto-correction, including trailing slashes, is enabled by default.
pub fn get(&mut self, path: &str, handle: T)
[src]
pub fn get(&mut self, path: &str, handle: T)
get is a shortcut for router.handle("GET", path, handle)
pub fn head(&mut self, path: &str, handle: T)
[src]
pub fn head(&mut self, path: &str, handle: T)
head is a shortcut for router.handle("HEAD", path, handle)
pub fn options(&mut self, path: &str, handle: T)
[src]
pub fn options(&mut self, path: &str, handle: T)
options is a shortcut for router.handle("OPTIONS", path, handle)
pub fn post(&mut self, path: &str, handle: T)
[src]
pub fn post(&mut self, path: &str, handle: T)
post is a shortcut for router.handle("POST", path, handle)
pub fn put(&mut self, path: &str, handle: T)
[src]
pub fn put(&mut self, path: &str, handle: T)
put is a shortcut for router.handle("PUT", path, handle)
pub fn patch(&mut self, path: &str, handle: T)
[src]
pub fn patch(&mut self, path: &str, handle: T)
patch is a shortcut for router.handle("PATCH", path, handle)
pub fn delete(&mut self, path: &str, handle: T)
[src]
pub fn delete(&mut self, path: &str, handle: T)
delete is a shortcut for router.handle("DELETE", path, handle)
pub fn group()
[src]
pub fn group()
Unimplemented. Perhaps something like
Example
router.group(vec![middelware], |router| { router.get("/something", somewhere); router.post("/something", somewhere); })
pub fn handle(&mut self, method: &str, path: &str, handle: T)
[src]
pub fn handle(&mut self, method: &str, path: &str, handle: T)
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).
pub fn lookup(&mut self, method: &str, path: &str) -> (Option<&T>, Params, bool)
[src]
pub fn lookup(&mut self, method: &str, path: &str) -> (Option<&T>, Params, bool)
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.
pub fn allowed(&self, path: &str, req_method: &str) -> String
[src]
pub fn allowed(&self, path: &str, req_method: &str) -> String
impl Router<Handler>
[src]
impl Router<Handler>
pub fn serve_files(&mut self, path: &str, root: &'static str)
[src]
pub fn serve_files(&mut self, path: &str, root: &'static str)
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]
impl Service for Router<Handler>
Service makes the router capable for Hyper.
type ReqBody = Body
The Payload
body of the http::Request
.
type ResBody = Body
The Payload
body of the http::Response
.
type Error = Error
The error type that can occur within this Service
. Read more
type Future = BoxFut
The Future
returned by this Service
.
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future
[src]
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future
call makes the router implement the Service
trait.
impl IntoFuture for Router<Handler>
[src]
impl IntoFuture for Router<Handler>
type Future = FutureResult<Self::Item, Self::Error>
The future that this type can be converted into.
type Item = Self
The item that the future may resolve with.
type Error = Error
The error that the future may resolve with.
fn into_future(self) -> Self::Future
[src]
fn into_future(self) -> Self::Future
Consumes this object and produces a future.