Coder Social home page Coder Social logo

dotnet-labs / semaphoreslimthrottle Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 8.0 20 KB

Rate Limiting API Endpoints in ASP.NET Core

License: MIT License

C# 100.00%
aspnetcore asp-net-core dotnet dotnetcore dotnet-core rate-limiting api http httpclient http-client throttle throttling concurrency concurrent http-request semaphore

semaphoreslimthrottle's Introduction

Rate Limiting API Endpoints in ASP.NET Core

Buy Me a Coffee at ko-fi.com

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.

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.

Buy Me a Coffee at ko-fi.com

semaphoreslimthrottle's People

Contributors

changhuixu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.