#actix-web-middleware #actix #actix-web #request #request-id

actix-request-identifier

Middlerware for actix-web to associate an ID with each request

4 releases (2 stable)

4.1.0 Jan 13, 2023
4.0.0 Aug 25, 2022
0.2.0 Oct 7, 2020
0.1.0 Apr 20, 2020

#236 in HTTP server

Download history 104/week @ 2023-10-29 134/week @ 2023-11-05 111/week @ 2023-11-12 156/week @ 2023-11-19 274/week @ 2023-11-26 365/week @ 2023-12-03 440/week @ 2023-12-10 155/week @ 2023-12-17 38/week @ 2023-12-24 59/week @ 2023-12-31 198/week @ 2024-01-07 182/week @ 2024-01-14 176/week @ 2024-01-21 138/week @ 2024-01-28 195/week @ 2024-02-04 211/week @ 2024-02-11

722 downloads per month
Used in 2 crates

Apache-2.0 OR MIT

19KB
282 lines

Actix Request Identifier Middleware

Latest Version Documentation Rust Hits-of-Code License License

actix-request-identifier implements a middleware for actix-web that generates an ID for each incomming request. By default, a UUID v4 is generated for each request using uuid. The request ID is set via the x-request-id HTTP header (which can be configured) and can be extracted from the request using RequestId.

Example

use actix_request_identifier::{RequestId, RequestIdentifier};
use actix_web::{get, App, HttpServer, Responder};

#[get("/")]
async fn show_request_id(id: RequestId) -> impl Responder {
    format!("{}", id.as_str())
}

#[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .service(show_request_id)
            .wrap(RequestIdentifier::with_uuid())
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

The response looks like this:

$ curl -i 127.0.0.1:8080/
HTTP/1.1 200 OK
content-length: 36
x-request-id: 5f099854-2117-49b3-b252-d6693a85acc5
date: Mon, 20 Apr 2020 06:53:49 GMT

5f099854-2117-49b3-b252-d6693a85acc5

Supported actix-web Versions

crate version actix-web version
0.1.0 v2
0.2.0 v3
4.0.0 v4

License

actix-request-identifier is licensed under either of the following at your option:

Dependencies

~17–30MB
~534K SLoC