#[route]Available on crate feature
macros only.Expand description
Annotate a handler function with its HTTP method and path.
On a classic handler (&Request, &PathParams, &ConnectionInfo[, state])
it adds a Route: METHOD /path doc comment and otherwise leaves the
function unchanged; register it with routes! or .get(). On a typed
handler (extractor arguments) it generates the adapter — see the crate
docs and rust_web_server::handler.
§Example
ⓘ
use rust_web_server::route;
use rust_web_server::request::Request;
use rust_web_server::router::PathParams;
use rust_web_server::server::ConnectionInfo;
use rust_web_server::response::Response;
use std::sync::Arc;
struct Db;
#[route(GET, "/users/:id")]
fn get_user(
req: &Request,
params: &PathParams,
conn: &ConnectionInfo,
state: &Arc<Db>,
) -> Response {
let id = params.get("id").unwrap_or("0");
Response::new()
}