README about the middleware and individual routes

This commit is contained in:
Romain Prieto 2014-08-26 11:00:59 +10:00
parent 8d92f4df7e
commit a9f3edd8c3

View file

@ -156,3 +156,24 @@ server.use(middleware);
It rejects any rate-limited requests with a status code of `HTTP 429`,
and an empty body.
*Note:* if you want to rate limit several routes individually, don't forget to use the route name as part of the `key`, for example using Restify:
```js
function ipAndRoute(req) {
return req.connection.remoteAddress + ':' + req.route.name;
}
server.get(
{name: 'routeA', path: '/a'},
rateLimiter.middleware({redis: client, key: ipAndRoute, rate: '10/minute'}),
controllerA
);
server.get(
{name: 'routeB', path: '/b'},
rateLimiter.middleware({redis: client, key: ipAndRoute, rate: '20/minute'}),
controllerB
);
```