Skip to content

Daniel Slocum#299

Open
daniel-slocum wants to merge 1 commit intocrexi-dev:masterfrom
daniel-slocum:master
Open

Daniel Slocum#299
daniel-slocum wants to merge 1 commit intocrexi-dev:masterfrom
daniel-slocum:master

Conversation

@daniel-slocum
Copy link

Adding and Using Rate Limiter Middleware

You can add the rate limiter and configure the rules through the rate limiter options.

// Add services to the container
builder.Services.AddRateLimiter(options =>
{
    // Configure rate limiter rules
    options.Rules.Add("/api/resource", new List<IRateLimitRule>
    {
        new RequestPerTimeSpanRule(5, TimeSpan.FromMinutes(1)), // Max 5 requests per minute
        new TimeSpanSinceLastRequestRule(TimeSpan.FromSeconds(10)) // At least 10 seconds between requests
    });
});

Once added, you can include the middleware in the request pipeline.

app.UseRateLimiter();

Rule Registration

Rules are tied to an endpoint, for example /api/resource, with support for multiple rules. You can include as many endpoints as desired. If a rule is not included, it is considered open and the request will be allowed. Current rule types supported are:

  • Maximum number of requests for X time span
  • Minimum of X time span between requests

The service is designed to run any new rules that are created and registered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant