Wrapper around reqwest to allow for client middleware chains.
Go to file
Ethan Brierley c54a7733b9 fix(lint): `clippy::doc_lazy_continuation`
```
error: doc list item missing indentation
Error:   --> reqwest-retry/src/middleware.rs:62:4
   |
62 | /// `Body`'s `From<String>` or `From<Bytes>` implementations.
   |    ^
   |
   = help: if this is supposed to be its own paragraph, add a blank line
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
   = note: `-D clippy::doc-lazy-continuation` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::doc_lazy_continuation)]`
help: indent this line
   |
62 | ///   `Body`'s `From<String>` or `From<Bytes>` implementations.
   |     ++

error: doc list item missing indentation
Error:   --> reqwest-retry/src/middleware.rs:65:4
   |
65 | /// source directly, avoiding the issue of streaming requests not being clonable.
   |    ^
   |
   = help: if this is supposed to be its own paragraph, add a blank line
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
help: indent this line
   |
65 | ///   source directly, avoiding the issue of streaming requests not being clonable.
   |     ++

error: could not compile `reqwest-retry` (lib) due to 2 previous errors
```
2024-07-29 20:28:02 +01:00
.cargo allow RUSTSEC-2020-0159 (#30) 2022-02-21 11:47:52 +00:00
.github fix: user-agent (#172) 2024-07-29 18:47:29 +01:00
reqwest-middleware chore: remove `reqwest-middleware` changelog from root (#166) 2024-06-28 10:51:33 +01:00
reqwest-retry fix(lint): `clippy::doc_lazy_continuation` 2024-07-29 20:28:02 +01:00
reqwest-tracing fix: user-agent (#172) 2024-07-29 18:47:29 +01:00
.gitignore Impl reqwest::Error methods (#96) 2023-08-07 10:34:01 +01:00
CHANGELOG.md chore: remove `reqwest-middleware` changelog from root (#166) 2024-06-28 10:51:33 +01:00
CODE_OF_CONDUCT.md Initial commit 2021-08-13 08:59:58 +01:00
CONTRIBUTING.md chore: remove `reqwest-middleware` changelog from root (#166) 2024-06-28 10:51:33 +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 reqwest 0.12 and other breaking changes (#135) 2024-04-03 18:13:10 +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:

Note about browser support: automated tests targeting wasm are disabled. The crate may work with wasm but wasm support is unmaintained. PRs improving wasm are still welcome but you'd need to reintroduce the tests and get them passing before we'd merge it (see https://github.com/TrueLayer/reqwest-middleware/pull/105).

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 = { version = "0.12", features = ["rustls-tls"] }
reqwest-middleware = "0.3"
reqwest-retry = "0.5"
reqwest-tracing = "0.5"
tokio = { version = "1.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::default())
        // 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.

Third-party middleware

The following third-party middleware use reqwest-middleware: