Struct fatcat_api_spec::router::Router [−][src]
pub struct Router { /* fields omitted */ }
Router
provides an interface for creating complex routes as middleware
for the Iron framework.
Methods
impl Router
[src]
impl Router
pub fn new() -> Router
[src]
pub fn new() -> Router
Construct a new, empty Router
.
let router = Router::new();
pub fn route<S, H, I>(
&mut self,
method: Method,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn route<S, H, I>(
&mut self,
method: Method,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
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, "user_friend");
route_id
is a unique name for your route, and is used when generating an URL with
url_for
.
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.
pub fn get<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn get<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Like route, but specialized to the Get
method.
pub fn post<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn post<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Like route, but specialized to the Post
method.
pub fn put<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn put<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Like route, but specialized to the Put
method.
pub fn delete<S, H, I>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn delete<S, H, I>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Like route, but specialized to the Delete
method.
pub fn head<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn head<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Like route, but specialized to the Head
method.
pub fn patch<S, H, I>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn patch<S, H, I>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Like route, but specialized to the Patch
method.
pub fn options<S, H, I>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn options<S, H, I>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Like route, but specialized to the Options
method.
pub fn any<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
[src]
pub fn any<S, H, I>(&mut self, glob: S, handler: H, route_id: I) -> &mut Router where
H: Handler,
I: AsRef<str>,
S: AsRef<str>,
Route will match any method, including gibberish. In case of ambiguity, handlers specific to methods will be preferred.
Trait Implementations
impl Handler for Router
[src]
impl Handler for Router
fn handle(&self, req: &mut Request) -> Result<Response, IronError>
[src]
fn handle(&self, req: &mut Request) -> Result<Response, IronError>
Produce a Response
from a Request, with the possibility of error.
impl Key for Router
[src]
impl Key for Router