RateLimit.Core 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package RateLimit.Core --version 1.0.1                
NuGet\Install-Package RateLimit.Core -Version 1.0.1                
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="RateLimit.Core" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RateLimit.Core --version 1.0.1                
#r "nuget: RateLimit.Core, 1.0.1"                
#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 RateLimit.Core as a Cake Addin
#addin nuget:?package=RateLimit.Core&version=1.0.1

// Install RateLimit.Core as a Cake Tool
#tool nuget:?package=RateLimit.Core&version=1.0.1                

Author: Khoi Tran

Package: RateLimit.Core

The .NET package provides a middleware service to protect your application by limit the request rate. If an IpAddress have number of request cross over the MaxRequestPerPeriod then it will be block by returning a TooManyRequest(429) in a mount of time (config by BlockTime in second)

Installation

nuget install RateLimit.Core

Usage

  • appsetting.json:
"RateLimit": {
    "CacheProvider": {
      "Redis": {
        "Host": "localhost:6379",
        "Database": 0,
        "ConnectTimeout": 4, // int: second
        "CacheTime": 3200 // int: second
      },
      "Memory": {
        "CacheTime": 3200 // int: second
      }
    },
    "PeriodTime": 10,
    "MaxRequestPerPeriod": 1,
    "BlockTime": 10,
    "Requests": [
      {
        "EndPoint": "/api/controller/end-point-1",
        "HeaderKey": ""
      },
      {
        "EndPoint": "/api/controller/end-point-2",
        "HeaderKey": "ServiceId"
      },
      {
        "EndPoint": "/api/controller/end-point-2",
        "HeaderKey": "ServiceId"
      }
    ]
  }
  • Startup.cs:
using RateLimit.Core;
using RateLimit.Core.Configs;

namespace WebApplication2
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            // ...
            services.AddRateLimit(Configuration, CacheType.Redis); // default is CacheType.Memory
            // ...
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // ...
            app.UseRateLimitMiddleware();
            // ...
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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.0.2 590 12/2/2022
1.0.1 316 12/2/2022
1.0.0 310 12/2/2022

Add README.md