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")]
#[handler(METHOD, "/path", middleware = [mw_fn, factory("arg")])]

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 #[middleware(...)] on the function, separate from the route registration attribute.