Wrapper around reqwest to allow for client middleware chains.
Go to file
Luca Palmieri 7489e2d4b7 Cut 0.2.0 release of `reqwest-tracing`. 2021-11-30 16:11:59 +00:00
.github Add support for OpenTelemetry 0.16 and tracing-opentelemetry 0.15 (#2) 2021-08-30 13:14:06 +02:00
reqwest-middleware chore: version bump reqwest-middleware to 0.1.2 (#10) 2021-09-28 19:57:28 +01:00
reqwest-retry chore(toml): update version field to the next 2021-10-18 16:54:38 +02:00
reqwest-tracing Cut 0.2.0 release of `reqwest-tracing`. 2021-11-30 16:11:59 +00:00
.gitignore Initial commit 2021-08-13 08:59:58 +01:00
CHANGELOG.md fix: remove security time v0.1 dependency (#16) 2021-10-18 16:24:36 +02:00
CODE_OF_CONDUCT.md Initial commit 2021-08-13 08:59:58 +01:00
CONTRIBUTING.md Initial commit 2021-08-13 08:59:58 +01:00
Cargo.toml Initial commit 2021-08-13 08:59:58 +01:00
LICENSE-APACHE Initial commit 2021-08-13 08:59:58 +01:00
LICENSE-MIT Initial commit 2021-08-13 08:59:58 +01:00
README.md fix: typo in readme (#13) 2021-09-30 15:13:18 +01:00

README.md

reqwest-middleware

A crate implementing a wrapper around reqwest to allow for client middleware chains.

Crates.io Docs.rs CI Coverage Status

This crate provides functionality for building and running middleware but no middleware implementations. This repository also contains a couple of useful concrete middleware crates:

Overview

The reqwest-middleware client exposes the same interface as a plain reqwest client, but ClientBuilder exposes functionality to attach middleware:

# Cargo.toml
# ...
[dependencies]
reqwest = "0.11"
reqwest-middleware = "0.1.1"
reqwest-retry = "0.1.1"
reqwest-tracing = "0.1.2"
tokio = { version = "1.12.0", features = ["macros", "rt-multi-thread"] }
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_retry::{RetryTransientMiddleware, policies::ExponentialBackoff};
use reqwest_tracing::TracingMiddleware;

#[tokio::main]
async fn main() {
    // Retry up to 3 times with increasing intervals between attempts.
    let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3);
    let client = ClientBuilder::new(reqwest::Client::new())
        // Trace HTTP requests. See the tracing crate to make use of these traces.
        .with(TracingMiddleware)
        // Retry failed requests.
        .with(RetryTransientMiddleware::new_with_policy(retry_policy))
        .build();
    run(client).await;
}

async fn run(client: ClientWithMiddleware) {
    client
        .get("https://truelayer.com")
        .header("foo", "bar")
        .send()
        .await
        .unwrap();
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.