#[handler]Expand description
Turns a function into a documented api handler
/// The first line is a `summary` available in openapi
///
/// The entire docstring is available as `description` in openapi
#[swaggapi::handler(Get, "/")]
async fn index() -> &'static str {
"Hello World"
}
/// Deletes the entire application's state
///
/// This endpoint is very dangerous and can only be used by admins.
#[swaggapi::delete("/deleteAll", tags("admin", "dangerous"))]
async fn delete_all() -> () {
// ...
}§Arguments
-
method: The HTTP method this handler should respond to- required
- one of
Get,Post,Put,Delete,Head,Options,Patch,Trace, for examplemethod = Get
-
path: The HTTP url this handler should respond onNote, the
ApiContextcan be used to apply a common prefix to a set of handlers.- required
- a string literal, for example
path = "/"
-
tags: A list of tags, mostly used to group handlersRead the OpenAPI specification for the full details
- optional
- list of string literal, for example
tags("foo", "bar)
§Positional arguments
Since method and path are required, they can alternatively be passed as positional arguments:
#[handler(Get, "/")]#[handler(Get, path = "/")]#[handler("/", method = Get)]
§Variants
The first argument method can be replaced with the usage of one specialized variant of #[handler]:
#[get(...)]is equivalent to#[handler(Get, ...)]#[post(...)]is equivalent to#[handler(Post, ...)]#[put(...)]is equivalent to#[handler(Put, ...)]#[delete(...)]is equivalent to#[handler(Delete, ...)]#[head(...)]is equivalent to#[handler(Head, ...)]#[options(...)]is equivalent to#[handler(Options, ...)]#[patch(...)]is equivalent to#[handler(Patch, ...)]#[trace(...)]is equivalent to#[handler(Trace, ...)]