pub struct Router { /* private fields */ }Expand description
Router provides an interface for creating complex routes as middleware
for the Ferrum framework.
Implementations§
Source§impl Router
impl Router
Sourcepub fn new() -> Router
pub fn new() -> Router
Construct a new, empty Router.
use ferrum_router::Router;
let router = Router::new();Examples found in repository?
More examples
Sourcepub fn route<G, H, S, T>(
&mut self,
method: Method,
glob: G,
handler: H,
route_id: Option<Id>,
) -> &mut Router
pub fn route<G, H, S, T>( &mut self, method: Method, glob: G, handler: H, route_id: Option<Id>, ) -> &mut Router
Add a new route to a Router, matching both a method and glob pattern.
route supports glob patterns based on the rust regex and uses {name} ({name: typename},
{name: pattern}) for matching storing named 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:[0-9]+}/{friendid:[0-9]+} and store userid and friend in
the exposed Params object:
let mut router = Router::new();
router.route(Method::Get, "/users/{userid:[0-9]+}/{friendid:[0-9]+}", controller, "user_friend");route_id is a optional unique name for your route, and is used when generating an URI 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.
Sourcepub fn get<G, H, S, T>(
&mut self,
glob: G,
handler: H,
route_id: Option<Id>,
) -> &mut Router
pub fn get<G, H, S, T>( &mut self, glob: G, handler: H, route_id: Option<Id>, ) -> &mut Router
Like route, but specialized to the Get method.
Examples found in repository?
More examples
Sourcepub fn post<G, H, S, T>(
&mut self,
glob: G,
handler: H,
route_id: Option<Id>,
) -> &mut Router
pub fn post<G, H, S, T>( &mut self, glob: G, handler: H, route_id: Option<Id>, ) -> &mut Router
Like route, but specialized to the Post method.
Sourcepub fn put<G, H, S, T>(
&mut self,
glob: G,
handler: H,
route_id: Option<Id>,
) -> &mut Router
pub fn put<G, H, S, T>( &mut self, glob: G, handler: H, route_id: Option<Id>, ) -> &mut Router
Like route, but specialized to the Put method.
Sourcepub fn delete<G, H, S, T>(
&mut self,
glob: G,
handler: H,
route_id: Option<Id>,
) -> &mut Router
pub fn delete<G, H, S, T>( &mut self, glob: G, handler: H, route_id: Option<Id>, ) -> &mut Router
Like route, but specialized to the Delete method.
Sourcepub fn head<G, H, S, T>(
&mut self,
glob: G,
handler: H,
route_id: Option<Id>,
) -> &mut Router
pub fn head<G, H, S, T>( &mut self, glob: G, handler: H, route_id: Option<Id>, ) -> &mut Router
Like route, but specialized to the Head method.
Sourcepub fn patch<G, H, S, T>(
&mut self,
glob: G,
handler: H,
route_id: Option<Id>,
) -> &mut Router
pub fn patch<G, H, S, T>( &mut self, glob: G, handler: H, route_id: Option<Id>, ) -> &mut Router
Like route, but specialized to the Patch method.