-
Notifications
You must be signed in to change notification settings - Fork 0
Add rate limiting support #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive rate limiting functionality to the FetchClient library, allowing developers to control request frequency with configurable limits and automatic header-based updates. The implementation includes support for both global and per-domain rate limiting with IETF standard compliance.
Key changes include:
- Implementation of core rate limiting logic with
RateLimiter
class andRateLimitMiddleware
- Integration with
FetchClientProvider
through new methods for enabling/managing rate limits - Support for automatic rate limit updates from response headers with fallback to legacy formats
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
src/RateLimiter.ts | Core rate limiting implementation with group-based buckets, IETF header parsing, and per-domain support |
src/RateLimitMiddleware.ts | Middleware integration that handles rate limit enforcement and error responses |
src/RateLimit.test.ts | Comprehensive test suite covering rate limiting functionality and header parsing |
src/FetchClientProvider.ts | Provider integration with useRateLimit and usePerDomainRateLimit methods |
src/FetchClient.test.ts | Integration tests for per-domain rate limiting with header auto-updates |
src/DefaultHelpers.ts | Helper functions for global rate limiting configuration |
readme.md | Documentation updates with rate limiting usage examples |
Co-authored-by: Copilot <[email protected]>
This pull request introduces rate limiting functionality to the
FetchClient
library, allowing developers to control the number of requests made within a specific time window. The changes include the addition of global and per-domain rate limiting, automatic updates from response headers, and enhanced error handling for rate limit violations. It also updates the documentation and tests to reflect these new features.New Features: Rate Limiting
Rate limiting middleware added:
RateLimitMiddleware
class to support rate limiting with configurable options such asmaxRequests
,windowSeconds
, and automatic updates from headers. It also provides IETF-compliant rate limit headers and error handling when limits are exceeded. (src/RateLimitMiddleware.ts
)useRateLimit
,usePerDomainRateLimit
, andremoveRateLimit
to theFetchClientProvider
class for enabling and managing rate limiting. (src/FetchClientProvider.ts
)Per-domain rate limiting:
src/FetchClientProvider.ts
)Documentation Updates
readme.md
:readme.md
) [1] [2]Code Enhancements
RateLimitMiddlewareOptions
type for configuring rate limiting options. (src/DefaultHelpers.ts
,src/FetchClientProvider.ts
) [1] [2]Testing Improvements
src/FetchClient.test.ts
)These changes provide robust support for rate limiting, making the
FetchClient
library more suitable for applications requiring controlled API usage.