| Crates.io | request_id_middleware |
| lib.rs | request_id_middleware |
| version | 0.3.1 |
| created_at | 2025-04-21 14:22:14.964871+00 |
| updated_at | 2025-04-23 13:13:34.542613+00 |
| description | Custom extractor for Rust Axum to extract the request id from an HTTP header X-Request-Id. |
| homepage | |
| repository | https://github.com/nebetoxyz/rust-request-id-middleware--lib |
| max_upload_size | |
| id | 1642700 |
| size | 30,385 |
Custom extractor for Rust Axum to extract the request id from an HTTP header X-Request-Id.
Works ONLY with Rust Axum.
use axum::{routing::get, Router};
use request_id_middleware::ExtractRequestId;
async fn handler(ExtractRequestId(request_id): ExtractRequestId) {
println!("Request Id: {:?}", request_id);
}
let app = Router::<()>::new().route("/foo", get(handler));
The extracted value is :
trim to clean extra spaces, before and after ;lowercase to standardize and make it more resilient to implementation errors.If the extracted value is not a valid UUID v7, it returns a 400 Bad Request with one of these two messages :
Invalid X-Request-Id : Not a valid UUID : it's a parsing error ;Invalid X-Request-Id : Not an UUID v7 : it's a version error.curl -H "X-Request-Id: 0196583c-4d2a-7087-9beb-6214d18ec924" http://api.nebeto.xyz/foo
curl -H "x-request-id: 0196583c-4d2a-7087-9beb-6214d18ec924" http://api.nebeto.xyz/foo
curl -H "X-ReQuest-ID: 0196583c-4d2a-7087-9beb-6214d18ec924" http://api.nebeto.xyz/foo
Will give for all 0196583c-4d2a-7087-9beb-6214d18ec924.
curl http://api.nebeto.xyz/foo
Will give by default a newly generated UUID v7 e.g. 0196583c-4d2a-7087-9beb-6214d18ec924.
For any question or feature suggestion, you can take a look and open, if necessary, a new discussion.
For any bug, you can take a look to our active issues and open, if necessary, a new issue.