Skip to content

Route details ​

Inference covers the shape of a route. Summaries, tags and the like are yours to add, either with the #[api] attribute or with Elysia-style Detail.

#[api] ​

#[api] attaches metadata without changing the handler.

rust
#[api(tag = "Users", summary = "List users", description = "Newest first")]
async fn list_users() -> Json<Vec<User>> {
    Json(Vec::new())
}

#[api(response(429, "Too many requests"))]
async fn search<E: SearchEngine>(Query(query): Query<Search>) -> Json<Vec<String>> {
    Json(E::hits(&query.tag))
}

#[api(tags(Users, Admin), operation_id = "purgeUsers", deprecated)]
async fn purge() -> NoContent {
    NoContent
}

#[api(hide)]
async fn health() -> &'static str {
    "ok"
}
OptionEffect
summary = ".."operation summary
description = ".."operation description
tag = "..", tags(A, B)tags
operation_id = ".."explicit operationId
response(429, "..")an extra documented status
deprecateddeprecated: true
hidekeep serving the route but leave it out of the document

#[api] also reads /// doc comments (the first line becomes the summary, the rest the description) and #[deprecated]. Without either, the summary comes from the function name: list_users becomes "List users".

Generic handlers work too, wherever they are declared, including inside a function body. #[api] cannot be placed on methods inside an impl block; use .detail(..) for those.

Detail ​

.detail(..) applies to the route registered just before it, or to every route of a group that was just closed, the same way as Elysia's detail:

rust
let app = ApiRouter::new()
    .get("/tenant", tenant)
    .detail(&Detail::new().summary("Echo the tenant").tag("Tenants"))

Detail takes .summary(..), .description(..), .tag(..), .operation_id(..), .deprecated(), .hide(), .security(..) and .response(status, description).

Groups and guards ​

group mounts routes under a prefix. Inside it, .tag(..) tags the routes added after it and .guard(..) applies a Detail to them, like Elysia's guard. Both end with the group.

rust
.group("/users", |users| {
    users
        .tag("Users")
        .get("/", list_users)
        .post("/", create_user)
        .get("/{id}", find_user)
})
.group("/admin", |admin| {
    admin
        .guard(Detail::new().tag("Admin"))
        .delete("/users", purge)
})

TIP

Inside group, a route at "/" maps to the group prefix itself, so /users above, not /users/.

Plain axum routers ​

map_router(..) gives you the underlying axum::Router for layers and anything else axum offers. Routes added there are served but not documented.

Released under the MIT or Apache-2.0 license.