Skip to content

Parse IETF RateLimit headers for proactive rate limit awareness in .NET HttpClient and Polly pipelines.

License

Notifications You must be signed in to change notification settings

Alos-no/RateLimitHeaders

Repository files navigation

RateLimitHeaders

Build Status Documentation License: MIT

NuGet (RateLimitHeaders) NuGet (RateLimitHeaders.Polly)

RateLimitHeaders is a .NET library for parsing IETF RateLimit headers and enabling proactive rate limit awareness in HTTP clients. It automatically delays requests before hitting 429 errors, integrates with Polly v8 resilience pipelines, and provides a drop-in DelegatingHandler for IHttpClientFactory.

Documentation | Getting Started | API Reference

Packages

Package Description
RateLimitHeaders Core library with IETF header parsing and IHttpClientFactory DelegatingHandler
RateLimitHeaders.Polly Polly v8 resilience pipeline integration
dotnet add package RateLimitHeaders
dotnet add package RateLimitHeaders.Polly  # Optional: for Polly integration

Example

// Register with IHttpClientFactory
services.AddHttpClient("MyApi")
    .AddRateLimitAwareHandler(options =>
    {
        options.EnableProactiveThrottling = true;
        options.QuotaLowThreshold = 0.1; // Warn at 10% remaining
    })
    .AddStandardResilienceHandler();

// Or use with Polly resilience pipelines
var pipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
    .AddRateLimitHeaders(options => options.EnableProactiveThrottling = true)
    .AddRetry(new RetryStrategyOptions<HttpResponseMessage>())
    .Build();

Features

  • IETF Standard Parsing - Parses RateLimit and RateLimit-Policy headers per draft-ietf-httpapi-ratelimit-headers-10

  • Proactive Throttling - Automatically delays requests when quota is low, preventing 429 errors before they happen

  • Polly Integration - Works seamlessly with Polly v8 resilience pipelines alongside retry and circuit breaker strategies

  • DelegatingHandler - Drop-in handler for IHttpClientFactory with full dependency injection support

  • Extensible - Implement IThrottlingAlgorithm for custom throttling strategies

  • Observable - Callbacks for rate limit info, quota warnings, and throttling events

Get Started

📚 Ready to dive in?

Explore the Full Documentation →

Comprehensive guides, configuration options, custom algorithms, and more.

Supported Frameworks

Package .NET 8 .NET 9 .NET 10
RateLimitHeaders Yes Yes Yes
RateLimitHeaders.Polly Yes Yes Yes

Contributing

We welcome contributions! Whether it's bug reports, feature requests, or code contributions.

License

This project is licensed under the MIT License.

Related Projects

About

Parse IETF RateLimit headers for proactive rate limit awareness in .NET HttpClient and Polly pipelines.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •