https://github.com/dotnet-labs/semaphoreslimthrottle
Rate Limiting API Endpoints in ASP.NET Core
https://github.com/dotnet-labs/semaphoreslimthrottle
api asp-net-core aspnetcore concurrency concurrent dotnet dotnet-core dotnetcore http http-client http-request httpclient rate-limiting semaphore throttle throttling
Last synced: 11 months ago
JSON representation
Rate Limiting API Endpoints in ASP.NET Core
- Host: GitHub
- URL: https://github.com/dotnet-labs/semaphoreslimthrottle
- Owner: dotnet-labs
- License: mit
- Created: 2020-07-09T12:34:56.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-13T03:27:37.000Z (about 5 years ago)
- Last Synced: 2025-04-11T01:39:52.833Z (about 1 year ago)
- Topics: api, asp-net-core, aspnetcore, concurrency, concurrent, dotnet, dotnet-core, dotnetcore, http, http-client, http-request, httpclient, rate-limiting, semaphore, throttle, throttling
- Language: C#
- Homepage:
- Size: 19.5 KB
- Stars: 20
- Watchers: 1
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Rate Limiting API Endpoints in ASP.NET Core
## [Medium Post 1: Rate Limiting API Endpoints in ASP.NET Core](https://medium.com/@changhuixu/rate-limiting-api-endpoints-in-asp-net-core-926e31428017)
This post shows (1) an ASP.NET Core Web API demo project which limits inbound HTTP requests from the internet and (2) an integration test project which tests the Web API rate limit using a `TestServer` and an `HttpClient`. One of the integration tests shows an example approach to send concurrent API requests using a `Semaphore` in order to comply with the rate limit in the Web API application.
## [Medium Post 2: Throttling Concurrent Outgoing HTTP Requests in .NET Core](https://medium.com/@changhuixu/throttling-concurrent-outgoing-http-requests-in-net-core-404b5acd987b)
This post will go over how to make concurrent outgoing HTTP requests _on the client side_. The goal is to let the HTTP Client send concurrent requests at the maximum allowed rate which is set by the server, for example, at a maximum rate of 2 requests per second.
## Solution Structure
This solution contains 3 projects.
1 `ThrottledWebApi`
- An ASP.NET Core Web API project
- Contains one API endpoint: `/api/values/isPrime?number={number}`
- The API endpoint is enforced with rate limit
2 `ThrottledWebApi.IntegrationTests`
- An integration test project with an in-memory test server
- An HTTP client is used to test against the API endpoint
- The rate limiting effect in different scenarios are tested
3 `ThrottledWebApi.ClientDemo`
- A .NET Core Console app with Dependency Injection, HttpClient
- Throttling concurrent outgoing HTTP requests using a `semaphore`
## License
Feel free to use the code in this repository as it is under MIT license.