Git Product home page Git Product logo

throttlebird's Introduction

 ______  __ __  ____    ___   ______  ______  _        ___  ____   ____  ____   ___   
|      T|  T  T|    \  /   \ |      T|      T| T      /  _]|    \ l    j|    \ |   \  
|      ||  l  ||  D  )Y     Y|      ||      || |     /  [_ |  o  ) |  T |  D  )|    \ 
l_j  l_j|  _  ||    / |  O  |l_j  l_jl_j  l_j| l___ Y    _]|     T |  | |    / |  D  Y
  |  |  |  |  ||    \ |     |  |  |    |  |  |     T|   [_ |  O  | |  | |    \ |     |
  |  |  |  |  ||  .  Yl     !  |  |    |  |  |     ||     T|     | j  l |  .  Y|     |
  l__j  l__j__jl__j\_j \___/   l__j    l__j  l_____jl_____jl_____j|____jl__j\_jl_____j

Throttlebird

Throttlebird is a simple http request throttler to help limit the number of client requests within a given period of time.

NuGet version Build status

Example

In your WebApiConfig file under the App_Start folder of your ASP.NET MVC project, add the following code block within the Register method:

// Implement our custom throttling handler to limit API method calls.
// Specify the throttle store, max number of allowed requests within specified timespan,
// and message displayed in the error response when exceeded.
config.MessageHandlers.Add(new ThrottlingHandler(
    new InMemoryThrottleStore(),
    id => 3,
    TimeSpan.FromSeconds(5),
    "You have exceeded the maximum number of allowed calls. Please wait until after the cooldown period to try again."
));

This works across all http requests on your site, limiting the number of requests to 3 every 5 seconds. To adjust, simply modify the id parameter to the number of requests, and the timespan to any valid TimeSpan value (FromSeconds, FromMinutes, etc.) to the values that work for you.

More to Come

This is the the first iteration of this library. Future expansions will allow you to selectively apply throttling on specific controller actions through the use of attributes.

throttlebird's People

Contributors

joelhulen 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.