{"id":15674561,"url":"https://github.com/mre/rate-limits","last_synced_at":"2025-05-06T22:07:22.169Z","repository":{"id":38183961,"uuid":"473813691","full_name":"mre/rate-limits","owner":"mre","description":"Parse HTTP Rate-Limit headers of different vendors","archived":false,"fork":false,"pushed_at":"2023-09-15T15:46:23.000Z","size":72,"stargazers_count":15,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T22:04:51.199Z","etag":null,"topics":["http","parser","rate-limit","rate-limiting"],"latest_commit_sha":null,"homepage":"https://docs.rs/rate-limits","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-25T00:15:35.000Z","updated_at":"2025-03-26T08:35:36.000Z","dependencies_parsed_at":"2024-06-11T21:50:22.566Z","dependency_job_id":null,"html_url":"https://github.com/mre/rate-limits","commit_stats":{"total_commits":51,"total_committers":1,"mean_commits":51.0,"dds":0.0,"last_synced_commit":"7b5a6eeb90da85f9a369cef705c526ba123df1e8"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Frate-limits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Frate-limits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Frate-limits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Frate-limits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mre","download_url":"https://codeload.github.com/mre/rate-limits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776579,"owners_count":21802467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","parser","rate-limit","rate-limiting"],"created_at":"2024-10-03T15:46:49.365Z","updated_at":"2025-05-06T22:07:22.152Z","avatar_url":"https://github.com/mre.png","language":"Rust","readme":"# rate-limits\n\n[![docs.rs](https://docs.rs/rate-limits/badge.svg)](https://docs.rs/rate-limits)\n\nA crate for parsing HTTP rate limit headers as per the [IETF draft][draft].\nInofficial implementations like the [Github rate limit headers][github] are\nalso supported on a best effort basis. See [vendor list] for support.\n\n```rust\nuse indoc::indoc;\nuse std::str::FromStr;\nuse time::{OffsetDateTime, Duration};\nuse rate_limits::{Vendor, RateLimit, ResetTime, Headers};\n\nlet headers = indoc! {\"\n    x-ratelimit-limit: 5000\n    x-ratelimit-remaining: 4987\n    x-ratelimit-reset: 1350085394\n\"};\n\nassert_eq!(\n    RateLimit::new(headers).unwrap(),\n    RateLimit::Rfc6585(Headers {\n        limit: 5000,\n        remaining: 4987,\n        reset: ResetTime::DateTime(\n            OffsetDateTime::from_unix_timestamp(1350085394).unwrap()\n        ),\n        window: Some(Duration::HOUR),\n        vendor: Vendor::Github\n    }),\n);\n```\n\nAlso takes the `Retry-After` header into account when calculating the reset\ntime.\n\n[`http::HeaderMap`][headermap] is supported as well:\n\n```rust\nuse std::str::FromStr;\nuse time::{OffsetDateTime, Duration};\nuse rate_limits::{Vendor, RateLimit, ResetTime, Headers};\nuse http::header::HeaderMap;\n\nlet mut headers = HeaderMap::new();\nheaders.insert(\"X-RATELIMIT-LIMIT\", \"5000\".parse().unwrap());\nheaders.insert(\"X-RATELIMIT-REMAINING\", \"4987\".parse().unwrap());\nheaders.insert(\"X-RATELIMIT-RESET\", \"1350085394\".parse().unwrap());\n\nassert_eq!(\n    RateLimit::new(headers).unwrap(),\n    RateLimit::Rfc6585(Headers {\n        limit: 5000,\n        remaining: 4987,\n        reset: ResetTime::DateTime(\n            OffsetDateTime::from_unix_timestamp(1350085394).unwrap()\n        ),\n        window: Some(Duration::HOUR),\n        vendor: Vendor::Github\n    }),\n);\n```\n\n### Further development\n\nThere is a new [IETF draft][draft_new] which supersedes the old \"polli\" draft.\nIt introduces a new `RateLimit-Policy` header which specifies the rate limit\nquota policy. The goal is to support this new draft in this crate as well.\n\n### Other resources:\n\n- [Examples of HTTP API Rate Limiting HTTP Response][stackoverflow]\n\n[draft]: https://datatracker.ietf.org/doc/html/draft-polli-ratelimit-headers-00\n[draft_new]: https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/\n[headers]: https://stackoverflow.com/a/16022625/270334\n[github]: https://docs.github.com/en/rest/overview/resources-in-the-rest-api\n[vendor list]: https://docs.rs/rate-limits/latest/rate_limits/enum.Vendor.html\n[stackoverflow]: https://stackoverflow.com/questions/16022624/examples-of-http-api-rate-limiting-http-response-headers\n[headermap]: https://docs.rs/http/latest/http/header/struct.HeaderMap.html\n\nLicense: Apache-2.0/MIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2Frate-limits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmre%2Frate-limits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2Frate-limits/lists"}