#axum #utoipa #bindings

utoipa-axum

Utoipa's axum bindings for seamless integration for the two

3 releases

0.1.0-beta.2 Sep 4, 2024
0.1.0-beta.1 Sep 2, 2024
0.1.0-beta.0 Sep 1, 2024

#1695 in Web programming

Download history 418/week @ 2024-09-01 49/week @ 2024-09-08

467 downloads per month

MIT/Apache

355KB
5.5K SLoC

utoipa-axum - Bindings for Axum and utoipa

Utoipa build crates.io docs.rs rustc

Utoipa axum brings utoipa and axum closer together by the way of providing an ergonomic API that is extending on the axum API. It gives a natural way to register handlers known to axum and also simultaneously generates OpenAPI specification from the handlers.

Crate features

  • debug: Implement debug traits for types.

Install

Add dependency declaration to Cargo.toml.

[dependencies]
utoipa_axum = "0.1"

Examples

Use OpenApiRouter to collect handlers with #[utoipa::path] macro to compose service and form OpenAPI spec.

#[derive(utoipa::ToSchema)]
struct Todo {
    id: i32,
}

#[derive(utoipa::OpenApi)]
#[openapi(components(schemas(Todo)))]
struct Api;

let mut router: OpenApiRouter = OpenApiRouter::with_openapi(Api::openapi())
    .routes(routes!(search_user))
    .routes(routes!(get_user, post_user, delete_user));

let api = router.to_openapi();
let axum_router: axum::Router = router.into();

License

Licensed under either of Apache 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be dual licensed, without any additional terms or conditions.

Dependencies

~3.5–5MB
~97K SLoC