macro_rules! middlefiddle {
(
router => $router:expr,
routes => {
$(
$route_id:ident: $route_method:ident $route:expr => $route_handler:expr
),+
$(,)*
},
middleware => {
$(
$middleware_type:expr => $middleware_handler:expr
),*
$(,)*
}
$(,)*
) => { ... };
}Expand description
The main iron_middlefiddle macro.
middlefiddle! {
// Pass the router you want the routes to be added to to `router`:
router => some_router,
// `routes` takes one or more routes. Each one of them will have every
// piece of middleware in `middleware` applied to them:
routes => {
// An example route that follows the formatting
// `route_id: method "/an/example/path" => controller`:
lorem: get "/lorem" => controllers::lorem::index,
// There can be as many of these as you like…
},
// `middleware` takes all of the middlewares you want to apply to each
// of the routes specified above.
middleware => {
// An example `BeforeMiddleware`:
Middleware::BeforeMiddleware => middleware::SomeBeforeMiddleware,
// An example `AfterMiddleware`:
Middleware::AfterMiddleware => middleware::SomeAfterMiddleware,
// There can be as many of these as you like…
},
};§Notes
-
The formatting of the contents of
routes => { ... }intentionally matches that of the router crate’s own router macro in an effort to make any potential refactoring easier. -
$route_methodsupports the following methods (must be lowercase):getpostputdeleteheadpatchoptionsany