Macro goohttp::impl_routes
source · macro_rules! impl_routes { { $group_id:tt { $ ( $route:tt, $request_type:tt $(, $parameters:expr)? ); * ; } } => { ... }; }
Expand description
Use this macro to create new routes.
To create a new group of routes, use the impl_route_group macro.
Example
Each route requires an associated function, which must be declared in its own module.
…/info/index.rs
pub async fn index() -> impl IntoResponse {
// Implementation of this function
}…/info/get_log.rs
pub async fn get_log(Path(mcserver): Path<String>) -> impl IntoResponse {
// Implementation of this function
}The parent module defines a router that can be nested by other routers. This router will then implement all specified routes and their associated functions.
…/info/mod.rs
impl_routes! {
info {
index, get; // Any function called indexed will be interpreted as the root route `/`.
index, get, ":username/:password";
get_log, get, ":mcserver"; // The second argument `get` can also be replaced by any other function from `axum::routing::*`.
}
}This macro allows you to skip writing the code below:
use goohttp::axum::*;
mod index;
mod get_log;
pub fn info() -> Router {
Router::new()
.route("/", get(index::index))
.route("/get_log/:mcserver", get(get_log::get_log))
}