Wrapper around reqwest to allow for client middleware chains.
Find a file
Rodrigo Gryzinski 7fe55152ec Initial commit
2021-08-13 08:59:58 +01:00
.github Initial commit 2021-08-13 08:59:58 +01:00
reqwest-middleware Initial commit 2021-08-13 08:59:58 +01:00
reqwest-retry Initial commit 2021-08-13 08:59:58 +01:00
reqwest-tracing Initial commit 2021-08-13 08:59:58 +01:00
.gitignore Initial commit 2021-08-13 08:59:58 +01:00
Cargo.toml Initial commit 2021-08-13 08:59:58 +01:00
CHANGELOG.md Initial commit 2021-08-13 08:59:58 +01: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
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 Initial commit 2021-08-13 08:59:58 +01:00

reqwest-middleware

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

Crates.io Docs.rs CI Coverage Status

Overview

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

use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_retry::{RetryTransientMiddleware, policies::ExponentialBackoff};
use reqwest_tracing::TracingMiddleware;

#[tokio::main]
async fn main() {
    let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3);
    let client = ClientBuilder::new(reqwest::Client::new())
        .with(TracingMiddleware)
        .with(RetryTransientMiddleware::new_with_policy(retry_policy))
        .build();
    run(client).await;
}

async fn run(client: ClientWithMiddleware) {
    // free retries!
    client
        .get("https://some-external-service.com")
        .header("foo", "bar")
        .send()
        .await
        .unwrap();
}

How to install

Add reqwest-middleware to your dependencies

[dependencies]
# ...
reqwest-middleware = "0.1.0"

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.