Getting started with Allure Reqwest
Capture reqwest HTTP requests and responses as attachments in your Allure Report test reports.
allure-reqwest works with any Rust test integration that provides an Allure facade — currently Rust Cargo Test — or with allure-rust-commons directly.
INFO
The official allure-rust repository also publishes allure-diesel for recording executed Diesel queries as Allure steps.
Setting up
Make sure you have an Allure integration set up for your test runner. See Rust Cargo Test.
Choose an integration style and add the dependency.
Middleware — recommended for broad capture with minimal call-site changes. It wraps a
reqwest_middleware::ClientWithMiddleware, so requests keep using a reqwest-style client while Allure records them automatically. Requires themiddlewarefeature and thereqwest-middlewarecrate:bashcargo add allure-reqwest --features middleware cargo add reqwest-middlewarerustuse allure_reqwest::AllureReqwestMiddleware; use reqwest_middleware::ClientBuilder; async fn create_order(allure: allure_rust_commons::AllureFacade) -> reqwest::Result<()> { let client = ClientBuilder::new(reqwest::Client::new()) .with(AllureReqwestMiddleware::new(allure)) .build(); let response = client .post("https://api.example.com/v1/orders") .header("content-type", "application/json") .body(r#"{"name":"demo"}"#) .send() .await?; response.error_for_status()?; Ok(()) }Wrapper client — the smaller alternative when you don't want the
reqwest-middlewaredependency, or only need to instrument selected calls. Requests must go throughAllureReqwestClient::send/executeinstead of a plainreqwest::Client:bashcargo add allure-reqwestrustuse allure_reqwest::AllureReqwestClient; async fn create_order(allure: allure_rust_commons::AllureFacade) -> reqwest::Result<()> { let client = AllureReqwestClient::new(allure); let response = client .send( client .post("https://api.example.com/v1/orders") .header("content-type", "application/json") .body(r#"{"name":"demo"}"#), ) .await?; response.error_for_status()?; Ok(()) }Both styles take an
allure_rust_commons::AllureFacade. Inside a#[allure_test]function, that's the injectedallurevalue; outside one, useallure_rust_commons::current_allure()or pass the facade through explicitly.Run your tests and generate a report the same way as you would normally — see Rust Cargo Test.
Every request made through an instrumented client is recorded as an HTTP exchange attachment, wrapped in a step (named HTTP Exchange by default). The attachment captures the request method, URL, query parameters, and headers; the response status, status text, and headers; the exchange start and stop timestamps; and, when the request fails, the error name and message. Request bodies are captured by default (up to a size limit); response bodies are opt-in. See the attachment schema reference for the exact field list.
INFO
To prevent secrets from leaking into reports, a default set of headers and query parameters is redacted before the attachment is written. See Allure Reqwest configuration for the full list of defaults and how to add to them.