| Crates.io | axum-accept |
| lib.rs | axum-accept |
| version | 0.0.5 |
| created_at | 2025-07-07 13:31:36.778014+00 |
| updated_at | 2025-07-08 15:34:51.066642+00 |
| description | Typed accept negotiation for axum. |
| homepage | |
| repository | https://github.com/bahlo/axum-accept |
| max_upload_size | |
| id | 1741280 |
| size | 23,522 |
Typed accept negotiation for axum, following RFC7231.
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(),
}
}
Licensed under either of
at your option.