Crate surf_governor

Crate surf_governor 

Source
Expand description

A surf middleware that implements rate-limiting using governor. The majority of this has been copied from tide-governor

§Example

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 Surf client with a governor
    let client = Client::new().with(GovernorMiddleware::per_second(30)?);
    let res = client.send(req).await?;
    Ok(())
}

Structs§

GovernorMiddleware
Once the rate limit has been reached, the middleware will respond with status code 429 (too many requests) and a Retry-After header with the amount of time that needs to pass before another request will be allowed.