Skip to content

A simple httpclient middleware for rate limiting. This library supports dependency injection and chaining with such libraries as Polly.

License

Notifications You must be signed in to change notification settings

andyjmorgan/DonkeyWork.Dev.SimpleRateLimiter

Repository files navigation

SimpleRateLimiter for HttpClient

build codeql

SimpleRateLimiter is a simple threadsafe HttpClient middleware for rate limiting. This library supports dependency injection and chaining with such libraries as Polly.

SimpleRateLimiter is threadsafe and can support concurrent access.

To use in a console application: (with a per second limit of 10):

new HttpClient(new SimpleRateLimitHandler(requestsPerSecond: 10))
{
    BaseAddress = new Uri(Properties.Resources.BaseAddress)
};

To use with Dependency Injection:

builderContext.Configuration.GetValue<string>("HttpClientName", "DonkeyWork")!)
  .ConfigureHttpClient(options =>
  {
      options.BaseAddress = new Uri(builderContext.Configuration.GetValue<string>("BaseAddress")!);
  })
  .AddHttpMessageHandler(() =>
      new SimpleRateLimitHandler(
          requestsPerSecond: 10));

About

A simple httpclient middleware for rate limiting. This library supports dependency injection and chaining with such libraries as Polly.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages