Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

ratelimit

Rate limiter middleware

Subscribe to updates I use ratelimit


Statistics on ratelimit

Number of watchers on Github 221
Number of open issues 6
Average time to close an issue 4 months
Main language JavaScript
Average time to merge a PR 20 days
Open pull requests 6+
Closed pull requests 9+
Last commit over 2 years ago
Repo Created almost 6 years ago
Repo Last Updated over 1 year ago
Size 33 KB
Organization / Authorkoajs
Contributors7
Page Updated
Do you use ratelimit? Leave a review!
View open issues (6)
View ratelimit activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating ratelimit for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

koa-ratelimit

NPM version build status node version

Rate limiter middleware for koa.

Installation

$ npm install koa-ratelimit

Example

const Koa = require('koa');
const ratelimit = require('koa-ratelimit');
const Redis = require('ioredis');
const app = new Koa();

// apply rate limit

app.use(ratelimit({
  db: new Redis(),
  duration: 60000,
  errorMessage: 'Sometimes You Just Have to Slow Down.',
  id: (ctx) => ctx.ip,
  headers: {
    remaining: 'Rate-Limit-Remaining',
    reset: 'Rate-Limit-Reset',
    total: 'Rate-Limit-Total'
  },
  max: 100
}));

// response middleware

app.use(async (ctx) => {
  ctx.body = 'Stuff!';
});

app.listen(3000);
console.log('listening on port 3000');

Options

  • db redis connection instance
  • duration of limit in milliseconds [3600000]
  • errorMessage custom error message
  • id id to compare requests [ip]
  • headers custom header names
  • max max requests within duration [2500]
    • remaining remaining number of requests ['X-RateLimit-Remaining']
    • reset reset timestamp ['X-RateLimit-Reset']
    • total total number of requests ['X-RateLimit-Limit']

Responses

Example 200 with header fields:

HTTP/1.1 200 OK
X-Powered-By: koa
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1384377793
Content-Type: text/plain; charset=utf-8
Content-Length: 6
Date: Wed, 13 Nov 2013 21:22:13 GMT
Connection: keep-alive

Stuff!

Example 429 response:

HTTP/1.1 429 Too Many Requests
X-Powered-By: koa
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1384377716
Content-Type: text/plain; charset=utf-8
Content-Length: 39
Retry-After: 7
Date: Wed, 13 Nov 2013 21:21:48 GMT
Connection: keep-alive

Rate limit exceeded, retry in 8 seconds

License

MIT

ratelimit open issues Ask a question     (View All Issues)
  • almost 6 years blacklist
  • almost 6 years whitelist
ratelimit open pull requests (View All Pulls)
  • Added ES6/ES7 await/async koa@next support, Updated tests, Added whitelist (closes #1), Added blacklist (closes #2)
  • Add option to throw error instead of setting body
  • Added support for custom error message
  • Update to koa 2
  • Add conditional option shouldRunFn to allow skipping ratelimit
  • add opts.disableHeader support and fix test error for custom error message
ratelimit questions on Stackoverflow (View All Questions)
  • How to set contentful.js api call rateLimit
  • Laravel 5 - RateLimit per IP address
  • nginx set remaining count for limit_req in X-RateLimit-Remaining header
  • RateLimit Bundle with Java
  • Django ratelimit for simple authentication returns no reverse match
  • How to make KnockoutJS throttle/ratelimit work conditionally?
  • cancel knockout ratelimit extender if user press Enter on an input
  • Subscribe callback triggers twice when use computed with notify and rateLimit extender
  • Vimeo -- rate limits header X-RateLimit-Limit -- CORS
  • RateLimit Exception for Amazon IO Error while using filepicker REST to upload images
  • ratelimit in django giving error Key 'rl:xxxx' not found
  • RateLimit issue with selenium scripts test run
  • Count views using django ratelimit per user
  • How to get X-RateLimit-Limit and X-Ratelimit-Remaining from Instagram gem response
  • Django RateLimit 403 Page Not Getting Replaced
  • Retrieve Twitter's X-RateLimit-Limit in PHP
ratelimit list of languages used
Other projects in JavaScript