7 releases

0.3.2 Oct 7, 2023
0.3.1 Aug 1, 2023
0.3.0 Jul 14, 2023
0.2.1 Nov 17, 2022
0.1.1 Jun 18, 2022

#852 in HTTP client

Download history 2652/week @ 2025-10-09 2956/week @ 2025-10-16 2347/week @ 2025-10-23 972/week @ 2025-10-30 891/week @ 2025-11-06 619/week @ 2025-11-13 463/week @ 2025-11-20 542/week @ 2025-11-27 1789/week @ 2025-12-04 1672/week @ 2025-12-11 926/week @ 2025-12-18 194/week @ 2025-12-25 1466/week @ 2026-01-01 1715/week @ 2026-01-08 1311/week @ 2026-01-15 1831/week @ 2026-01-22

6,359 downloads per month
Used in 2 crates (via tfc-toolset-extras)

MIT/Apache

10KB
137 lines

A [surf] middleware that handles request retry logic

Example

use surf_retry::{ExponentialBackoff, RetryMiddleware};
use surf_governor::GovernorMiddleware;
use surf::{Client, Request, http::Method};
use url::Url;

#[async_std::main]
async fn main() -> surf::Result<()> {
    let req = Request::new(Method::Get, Url::parse("https://example.api")?);
    // Construct the retry middleware with max retries set to 3, exponential backoff also set to a max of 3, and a fallback interval of 1 second
    let retry = RetryMiddleware::new(
       3,
       ExponentialBackoff::builder().build_with_max_retries(3),
       1,
       );
    // Construct Surf client with the retry middleware and a limit of 1 request per second to force a retry
    let client = Client::new().with(retry).with(GovernorMiddleware::per_second(1)?);
    let res = client.send(req).await?;
    Ok(())
}

surf-retry

A retry middleware for surf

Install

With cargo add installed :

cargo add surf-retry

Documentation

Example

use surf_retry::RetryMiddleware;
use surf::{Client, Request, http::Method};
use url::Url;

use std::time::Duration;

#[async_std::main]
async fn main() -> surf::Result<()> {
    let req = Request::new(Method::Get, Url::parse("https://example.api")?);
    let client = Client::new().with(RetryMiddleware::default());
    let res = client.send(req).await?;
    Ok(())
}

Dependencies

~12–20MB
~363K SLoC