From a9f3edd8c343c10462cc80a4bd02487718a776f7 Mon Sep 17 00:00:00 2001 From: Romain Prieto Date: Tue, 26 Aug 2014 11:00:59 +1000 Subject: [PATCH] README about the middleware and individual routes --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 928d05b..714b2d2 100644 --- a/README.md +++ b/README.md @@ -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 +); + +```