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§
- Governor
Middleware - Once the rate limit has been reached, the middleware will respond with
status code 429 (too many requests) and a
Retry-Afterheader with the amount of time that needs to pass before another request will be allowed.