macro_rules! http_router {
($($method:tt $path:literal => $h:expr),*) => { ... };
(@build $r:ident HEAD $path:literal => $h:expr) => { ... };
(@build $r:ident GET $path:literal => $h:expr) => { ... };
(@build $r:ident PUT $path:literal => $h:expr) => { ... };
(@build $r:ident POST $path:literal => $h:expr) => { ... };
(@build $r:ident PATCH $path:literal => $h:expr) => { ... };
(@build $r:ident DELETE $path:literal => $h:expr) => { ... };
(@build $r:ident OPTIONS $path:literal => $h:expr) => { ... };
(@build $r:ident _ $path:literal => $h:expr) => { ... };
}Expand description
A macro to help with constructing a Router from method-pattern-handler triples.
ยงExamples
fn handle_route(req: Request) -> Response {
let router = http_router! {
GET "/user" => list_users,
POST "/user" => create_user,
GET "/user/:id" => get_user,
PUT "/user/:id" => update_user,
DELETE "/user/:id" => delete_user,
_ "/user" => method_not_allowed,
_ "/user/:id" => method_not_allowed
};
router.handle(req)
}