#[api_description]Expand description
Defines an API as a trait, generating endpoint types and a Serves bridge.
Each method in the trait is annotated with an HTTP method attribute (#[get(...)],
#[post(...)], etc.) that specifies the path. The macro generates:
- A type alias
<TraitName>Spec— a tuple of endpoint types - The original trait with async method signatures
- An
into_handlersmethod that produces a handler tuple forServer::new
§Example
ⓘ
#[api_description]
trait UserAPI {
#[get("users" / u32)]
async fn get_user(path: Path<UserByIdPath>) -> Json<User>;
#[post("users")]
async fn create_user(body: Json<CreateUser>) -> Json<User>;
}
struct MyImpl { db: DbPool }
impl UserAPI for MyImpl {
async fn get_user(path: Path<UserByIdPath>) -> Json<User> {
let user = User { id: path.id, name: "Alice".into() };
Json(user)
}
async fn create_user(body: Json<CreateUser>) -> Json<User> {
let user = User { id: 1, name: body.0.name.clone() };
Json(user)
}
}
// Use: serve_user_api() bridges the trait impl to Server::new
Server::<UserAPISpec>::new(serve_user_api(MyImpl));