Crates.io | surf-governor |
lib.rs | surf-governor |
version | 0.2.0 |
source | src |
created_at | 2022-05-22 22:12:49.807533 |
updated_at | 2023-07-14 21:33:08.90036 |
description | A rate-limiting middleware for surf |
homepage | |
repository | https://github.com/06chaynes/surf-governor.git |
max_upload_size | |
id | 591467 |
size | 26,814 |
A rate-limiting middleware for surf
With cargo add installed :
cargo add surf-governor
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")?);
let client = Client::new().with(GovernorMiddleware::per_second(1)?);
let res = client.send(req).await?;
Ok(())
}