ApiRateLimiting 1.1.0

dotnet add package ApiRateLimiting --version 1.1.0                
NuGet\Install-Package ApiRateLimiting -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ApiRateLimiting" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ApiRateLimiting --version 1.1.0                
#r "nuget: ApiRateLimiting, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ApiRateLimiting as a Cake Addin
#addin nuget:?package=ApiRateLimiting&version=1.1.0

// Install ApiRateLimiting as a Cake Tool
#tool nuget:?package=ApiRateLimiting&version=1.1.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

  1. IP-based or User-based rate limiting: Supports rate limiting based on user identity or IP address.
  2. Customizable rules: Define custom rules for rate limiting, such as requests per minute, hour, or day.
  3. Memory-based storage: Uses an in-memory cache to track requests per user/IP.
  4. Configurable: Configure the rate limits and time periods via JSON configuration or programmatically.
  5. 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 --version 1.1.0. Alternatively, you can download it from the NuGet Gallery.

Key Steps:

  1. Create a blank project using the ASP.NET web api.

  2. Choose .NET 8.0 for the project.

  3. Install the ApiRateLimiting from NuGet packages. Install-Package ApiRateLimiting -Version 1.1.0

  4. Add code in the program.cs file:

    • Add namespace using ApiRateLimiting;.

    • Add

     builder.Services.Configure<IpRateLimitOptions>(builder.Configuration.GetSection("IpRateLimiting"));   
     builder.Services.AddApiRateLimiting();      
    
    • Add app.UseMiddleware<RateLimitingMiddleware>();.
  5. Update the application settings with the following configurations:

"IpRateLimiting": {
  "GeneralRules": [
    {
      "Endpoint": "WeatherForecast/weatherforecast",  //Set multiple endpoint 
      "Period": "2m",                                 //Set period day for d ,hour for h,min for m 
      "Limit": 1                                      // Set limit
    },
    {
      "Endpoint": "WeatherForecast/weatherforecast/v1",
      "Period": "2m",
      "Limit": 2
    },
    {
      "Endpoint": "WeatherForecast/weatherforecast/v2",
      "Period": "2m",     
      "Limit": 3
    }
  ]

}
  1. Run the project to complete the setup.

How It Works

  1. The rate limiting service tracks requests based on the user or IP address and stores the data in memory.
  2. The CustomRateLimitService checks if the number of requests exceeds the defined limit within the specified period (e.g., 100 requests per hour).
  3. If the limit is exceeded, the RateLimitFilter blocks the request and returns a 429 Too Many Requests response with rate limiting details.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 33 1/13/2025
1.0.0 32 1/12/2025