Struct 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]
fn new() -> Router
Construct a new, empty Router.
let router = Router::new();
fn route<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
method: Method,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
method: Method,
glob: S,
handler: H,
route_id: I
) -> &mut Router
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.
fn get<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Like route, but specialized to the Get method.
fn post<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Like route, but specialized to the Post method.
fn put<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Like route, but specialized to the Put method.
fn delete<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Like route, but specialized to the Delete method.
fn head<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Like route, but specialized to the Head method.
fn patch<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Like route, but specialized to the Patch method.
fn options<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Like route, but specialized to the Options method.
fn any<S: AsRef<str>, H: Handler, I: AsRef<str>>(
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
&mut self,
glob: S,
handler: H,
route_id: I
) -> &mut Router
Route will match any method, including gibberish. In case of ambiguity, handlers specific to methods will be preferred.
Trait Implementations
impl Key for Router[src]
impl Handler for Router[src]
fn handle(&self, req: &mut Request) -> IronResult<Response>
Produce a Response from a Request, with the possibility of error.