3 releases
Uses new Rust 2024
| 0.1.2 | Jul 11, 2025 |
|---|---|
| 0.1.1 | Jul 11, 2025 |
| 0.1.0 | Jul 11, 2025 |
#1393 in HTTP server
13KB
69 lines
actix-web-reqid
Tool to work with Request ID(UUID).
This crate is based on timtonk/actix-web-middleware-requestid.
Usage
Add the middleware to your Actix Web application to automatically generate and attach a UUID request ID to each incoming request.
1. Add the middleware
use actix_web::{App, HttpServer};
use actix_web_reqid::RequestIDWrapper;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.wrap(RequestIDWrapper)
// your routes here
})
.bind("127.0.0.1:8080")?
.run()
.await
}
2. Extract the request ID in your handler
use actix_web::{get, HttpResponse, Responder};
use actix_web_reqid::RequestID;
#[get("/")]
async fn index(request_id: RequestID) -> impl Responder {
HttpResponse::Ok().body(format!("Request ID: {}", request_id.0))
}
3. Error handling
If the request ID is missing, the extractor will return a 400 Bad Request error.
This middleware helps you trace requests by assigning a unique UUID to each request and making it accessible in your handlers.
Dependencies
~15–29MB
~444K SLoC