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));