pub async fn propagate_request_id(req: Request, next: Next) -> ResponseExpand description
Axum middleware that assigns a request correlation id and echoes it on the response.
It reuses an incoming x-request-id header when present (and non-empty), otherwise it
generates a UUID v4. The id is stored in request extensions (extractable via
RequestId) and written to the response x-request-id header. Requires the trace
feature.
ยงExample
use axum::{middleware, routing::get, Router};
use axum_api_kit::propagate_request_id;
let app: Router = Router::new()
.route("/", get(|| async { "ok" }))
.layer(middleware::from_fn(propagate_request_id));