Skip to main content

handler

Attribute Macro handler 

Source
#[handler]
Expand description

Registers an async function as an HTTP route handler.

ยงSyntax

#[handler(METHOD, "/path")]

Supported methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS.

Path parameters expressed as {name} in the route string are automatically extracted. Declare a matching function parameter by name and the macro rewrites the signature to use axum::extract::Path under the hood. Undeclared path params are captured but silently ignored (partial extraction).

Handler-level middleware is attached with a separate #[middleware(...)] attribute on the function. Bare paths are wrapped with axum::middleware::from_fn; paths followed by (args) are called as layer factories.

#[handler(GET, "/items/{id}")]
#[middleware(require_auth, require_role("admin"))]
async fn get_item(id: String) -> modo::JsonResult<Item> { ... }