Skip to content

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

Merged
merged 7 commits into from
Jul 18, 2025
Merged

Add rate limiting support #3

merged 7 commits into from
Jul 18, 2025

Conversation

ejsmith
Copy link
Member

@ejsmith ejsmith commented Jul 17, 2025

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:

    • Introduced the RateLimitMiddleware class to support rate limiting with configurable options such as maxRequests, windowSeconds, and automatic updates from headers. It also provides IETF-compliant rate limit headers and error handling when limits are exceeded. (src/RateLimitMiddleware.ts)
    • Added methods useRateLimit, usePerDomainRateLimit, and removeRateLimit to the FetchClientProvider class for enabling and managing rate limiting. (src/FetchClientProvider.ts)
  • Per-domain rate limiting:

    • Implemented per-domain rate limiting with support for auto-updating limits based on headers and domain-specific configurations. (src/FetchClientProvider.ts)

Documentation Updates

  • Updated readme.md:
    • Added sections for rate limiting, including examples for global and per-domain configurations, to guide developers on using the new feature. (readme.md) [1] [2]

Code Enhancements

  • Type additions:
    • Added RateLimitMiddlewareOptions type for configuring rate limiting options. (src/DefaultHelpers.ts, src/FetchClientProvider.ts) [1] [2]

Testing Improvements

  • New test cases:
    • Added tests to validate per-domain rate limiting functionality, including auto-updating limits based on headers and verifying the correct application of rate limit policies. (src/FetchClient.test.ts)

These changes provide robust support for rate limiting, making the FetchClient library more suitable for applications requiring controlled API usage.

Copy link
Contributor

@Copilot Copilot AI left a 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 and RateLimitMiddleware
  • 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

@ejsmith ejsmith merged commit 1f0679d into main Jul 18, 2025
4 checks passed
@niemyjski niemyjski deleted the rate-limit2 branch July 18, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants