Skip to main content

api_router

Attribute Macro api_router 

Source
#[api_router]
Expand description

Turns an inline module into a router.

Discovers the functions annotated with a route macro and generates a router() function that mounts them under the given prefix and tags.

§Example

#[api_router(prefix = "/users", tags = ["users"])]
pub mod users_router {
    use super::*;

    #[get("/{user_id}", response_model = UserOut)]
    pub async fn get_user(user_id: i64, service: UserService) -> tork::Result<UserOut> {
        service.get_user(user_id).await
    }
}
// `users_router::router()` is now available.