7次发布

0.3.2 2023年10月7日
0.3.1 2023年8月1日
0.3.0 2023年7月14日
0.2.1 2022年11月17日
0.1.1 2022年6月18日

#347 in HTTP客户端

Download history 9/week @ 2024-03-15 40/week @ 2024-03-22 72/week @ 2024-03-29 9/week @ 2024-04-05 19/week @ 2024-04-12 9/week @ 2024-04-19 2/week @ 2024-04-26 6/week @ 2024-05-10 5/week @ 2024-05-17 8/week @ 2024-05-24 3/week @ 2024-05-31 142/week @ 2024-06-07 28/week @ 2024-06-14 6/week @ 2024-06-21 4/week @ 2024-06-28

每月180次下载
2个crate中使用(通过tfc-toolset-extras

MIT/Apache

10KB
137

surf-retry

surf的retry中间件

安装

如果已安装cargo add

cargo add surf-retry

文档

示例

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(())
}

lib.rs:

一个处理请求重试逻辑的[surf]中间件

示例

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(())
}

依赖项

~10–23MB
~348K SLoC