mirror of
https://github.com/clechasseur/reessaie.git
synced 2025-12-14 11:58:55 +01:00
Companion to reqwest_retry to use the Retry-After HTTP header if available
|
|
||
|---|---|---|
| .github | ||
| src | ||
| tests | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CODE_OF_CONDUCT.md | ||
| codecov.yml | ||
| CONTRIBUTING.md | ||
| DEVELOPMENT.md | ||
| justfile | ||
| LICENSE | ||
| msrv-pins.toml | ||
| README.md | ||
| renovate.json | ||
| rustfmt.toml | ||
| SECURITY.md | ||
| tarpaulin.toml | ||
reessaie
Companion library to reqwest-retry with helpers to use the Retry-After HTTP header to control the time between retries, if it's available.
Partially inspired by reqwest-retry-after.
Installing
Add reessaie to your dependencies:
[dependencies]
reessaie = "3.0.0"
or by running:
cargo add reesaie
Example
use anyhow::Context;
use reessaie::{RetryAfterMiddleware, RetryAfterPolicy};
use reqwest::Client;
use reqwest_middleware::ClientBuilder;
async fn get_with_retries(url: &str, max_retries: u32) -> Result<String, anyhow::Error> {
let policy = RetryAfterPolicy::with_max_retries(max_retries);
let client = ClientBuilder::new(Client::new())
.with(RetryAfterMiddleware::new_with_policy(policy))
.build();
Ok(client
.get(url)
.send()
.await
.with_context(|| format!("error getting {url}"))?
.text()
.await
.with_context(|| format!("error getting text for {url}"))?)
}
For more information, see the docs.
Minimum Rust version
reessaie currently builds on Rust 1.88 or newer.