ApiRateLimiting 1.0.0
See the version list below for details.
dotnet add package ApiRateLimiting --version 1.0.0
NuGet\Install-Package ApiRateLimiting -Version 1.0.0
<PackageReference Include="ApiRateLimiting" Version="1.0.0" />
<PackageVersion Include="ApiRateLimiting" Version="1.0.0" />
<PackageReference Include="ApiRateLimiting" />
paket add ApiRateLimiting --version 1.0.0
#r "nuget: ApiRateLimiting, 1.0.0"
#:package ApiRateLimiting@1.0.0
#addin nuget:?package=ApiRateLimiting&version=1.0.0
#tool nuget:?package=ApiRateLimiting&version=1.0.0
API Rate Limiting Package
This is a simple API rate limiting middleware and service that allows you to limit the number of requests made by users or IP addresses within a specified time period.
Features
- IP-based or User-based rate limiting: Supports rate limiting based on user identity or IP address.
- Customizable rules: Define custom rules for rate limiting, such as requests per minute, hour, or day.
- Memory-based storage: Uses an in-memory cache to track requests per user/IP.
- Configurable: Configure the rate limits and time periods via JSON configuration or programmatically.
- Extensible: Easily extend the rate limiting logic or add custom features to fit your needs.
Installation
To install the package, use the dotnet add package ApiRateLimiting.
Alternatively, you can download it from the NuGet Gallery.
Key Steps:
Create a blank project using the ASP.NET web api.
Choose .NET 8.0 for the project.
Install the ApiRateLimiting from NuGet packages.
dotnet add package ApiRateLimitingAdd code in the program.cs file:
Add namespace
using ApiRateLimiting;.Add
builder.Services.Configure<IpRateLimitOptions>(builder.Configuration.GetSection("IpRateLimiting"));.Add
builder.Services.AddApiRateLimiting();.Add
app.UseMiddleware<RateLimitingMiddleware>();.
Update the application settings with the following configurations:
"IpRateLimiting": {
"GeneralRules": [
{
"Endpoint": "*",
"Period": "2m", //set min for m ,hour for h,day for d
"Limit": 2 // set request limit
}
]
}
- Run the project to complete the setup.
How It Works
- The rate limiting service tracks requests based on the user or IP address and stores the data in memory.
- The CustomRateLimitService checks if the number of requests exceeds the defined limit within the specified period (e.g., 100 requests per hour).
- The limit is exceeded, the RateLimitFilter blocks the request and returns a 429 Too Many Requests response with rate limiting details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- DynamicFormBuilder (>= 1.1.0)
- EntityFramework (>= 6.5.1)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.