High-performance rate limiting for .NET APIs. Token bucket, sliding window, fixed window, and concurrency limiting with ASP.NET Core middleware integration.
$ dotnet add package JG.RateLimiterHigh-performance rate limiting for .NET APIs. Supports token bucket, sliding window, fixed window, and concurrency limiting — with per-client and per-endpoint policies, pluggable storage for distributed state, and ASP.NET Core middleware integration.
[RateLimit] / [DisableRateLimiting]IRateLimitStore for Redis or other backendsRetry-After and X-RateLimit-* response headersservices.AddRateLimiting()dotnet add package JG.RateLimiter
using JG.RateLimiter;
using JG.RateLimiter.Policies;
builder.Services.AddRateLimiting(options =>
{
options.AddPolicy("api", new TokenBucketPolicy
{
PermitLimit = 100,
Window = TimeSpan.FromMinutes(1),
BurstLimit = 20,
PartitionBy = context => context.Connection.RemoteIpAddress?.ToString()
});
});
app.UseRouting();
app.UseRateLimiting();
app.MapControllers();
Contributions are welcome! Please feel free to submit a Pull Request.
Licensed under the Apache License 2.0. See LICENSE for details.
Ready to get started? Install via NuGet and check out the API reference.