The documentation states:
Note that you can always place this on per-URL routes to enable different request rates to different resources (if for example, one route, like /my/slow/database is much easier to overwhlem than /my/fast/memcache).
I am having trouble finding out how to implement this exactly.
Basically, I want to serve static files at a different throttle rate than my API.
Setup throttling (rate limiter) with restify for some endpoints like this.
var rateLimit = restify.throttle({burst:100,rate:50,ip:true});
server.get('/my/endpoint',
rateLimit,
function(req, res, next) {
// Do something here
return next();
}
);
server.post('/another/endpoint',
rateLimit,
function(req, res, next) {
// Do something here
return next();
}
);
Or like this.
server.post('/my/endpoint',
restify.throttle({burst:100,rate:50,ip:true}),
function(req, res, next) {
// Do something here
return next();
}
);
Even when throttling per endpoint a global throttle may still be desired, so that can be done like this.
server.use(restify.throttle({burst:100,rate:50,ip:true});
(reference) Throttle is one of restify's plugins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With