axum-accept 0.0.5

Typed accept negotiation for axum.
Documentation

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.