#[api_route]Expand description
Same as route, but with support for OpenApi using aide. See route for more
information and examples.
§Syntax
ⓘ
#[api_route(<METHOD> "<PATH>" [with <STATE>] [{
summary: "<SUMMARY>",
description: "<DESCRIPTION>",
id: "<ID>",
tags: ["<TAG>", ..],
hidden: <bool>,
security: { <SCHEME>: ["<SCOPE>", ..], .. },
responses: { <CODE>: <TYPE>, .. },
transform: |op| { .. },
}])]summaryis the OpenApi summary. If not specified, the first line of the function’s doc-commentsdescriptionis the OpenApi description. If not specified, the rest of the function’s doc-commentsidis the OpenApi operationId. If not specified, the function’s name is used.tagsare the OpenApi tags.hiddensets whether docs should be hidden for this route.securityis the OpenApi security requirements.responsesare the OpenApi responses.transformis a closure that takes anTransformOperationand returns anTransformOperation. This may override the other options. (see the crateaidefor more information).
§Example
use axum::extract::{State, Json};
use axum_typed_routing_macros::api_route;
#[api_route(GET "/item/:id?amount&offset" with String {
summary: "Get an item",
description: "Get an item by id",
id: "get-item",
tags: ["items"],
hidden: false,
security: { "bearer": ["read:items"] },
responses: { 200: String },
transform: |op| op.tag("private"),
})]
async fn item_handler(
id: u32,
amount: Option<u32>,
offset: Option<u32>,
State(state): State<String>,
) -> String {
todo!("handle request")
}