axum-accept

Crates.ioaxum-accept
lib.rsaxum-accept
version0.0.5
created_at2025-07-07 13:31:36.778014+00
updated_at2025-07-08 15:34:51.066642+00
descriptionTyped accept negotiation for axum.
homepage
repositoryhttps://github.com/bahlo/axum-accept
max_upload_size
id1741280
size23,522
Arne Bahlo (bahlo)

documentation

https://docs.rs/axum-accept

README

axum-accept

CI crates.io docs.rs License

Typed accept negotiation for axum, following RFC7231.

Example

use axum::{extract::Json, response::{IntoResponse, Response}};
use axum_accept::AcceptExtractor;
use serde_json::json;

#[derive(AcceptExtractor)]
enum Accept {
    #[accept(mediatype="text/plain")]
    TextPlain,
    #[accept(mediatype="application/json")]
    ApplicationJson,
}

async fn my_handler(accept: Accept) -> Response {
    match accept {
        Accept::TextPlain => "hello world".into_response(),
        Accept::ApplicationJson => Json(json!({ "content": "hello_world" })).into_response(),
    }
}

License

Licensed under either of

at your option.

Commit count: 0

cargo fmt