rate-limits

docs.rs

A crate for parsing HTTP rate limit headers as per the IETF draft. Inofficial implementations like the Github rate limit headers are also supported on a best effort basis. See [vendor list] for support.

```rust use indoc::indoc; use time::{OffsetDateTime, Duration}; use rate_limits::{Vendor, RateLimit, ResetTime};

let headers = indoc! {" x-ratelimit-limit: 5000 x-ratelimit-remaining: 4987 x-ratelimit-reset: 1350085394 "};

asserteq!( RateLimit::new(headers).unwrap(), RateLimit { limit: 5000, remaining: 4987, reset: ResetTime::DateTime( OffsetDateTime::fromunix_timestamp(1350085394).unwrap() ), window: Some(Duration::HOUR), vendor: Vendor::Github }, ); ```

Also takes the Retry-After into account when calculating the reset time.

Other resources:

Installation

cargo add rate-limits