Skip to content

argo/argo-rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

argo-rate-limiter

Rate limiting for argo.

Install

$ npm install argo-rate-limiter

Example

var argo = require('argo');
var limit = require('argo-rate-limiter');

// Allow 1 request every 5 seconds.
// Allow bursts of 2 requests every 5 seconds.
// In a burst, delay the excess request by 1 second.
var options = {
  capacity: 1,
  duration: 5000, // ms
  burst: 2,
  delay: 1000 //ms
};

argo()
  .use(limit(options))
  .get('/greeting', function(addHandler) {
    addHandler('request', function(env, next) {
      env.response.setHeader('Content-Type',  'text/plain');
      env.responseBody = 'Hello World!';
      next(env);
    });
  })
  .listen(process.env.PORT || 1337);

Usage

limit(options)

options.capacity

The number of requests allowed.

options.duration

The maximum time allowed to consume the requests at capacity (in milliseconds).

options.burst

The number of requests allowed in a burst scenario. Optional.

options.delay

A delay applied to excess requests in a burst (in milliseconds). Optional.

License

MIT

About

A rate limiter for argo-server.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published