Open AlexGilleran opened 6 years ago
Adding my note on rate limiting in #2883
Rate limiting is important to prevent the abuse of our API, since API keys are being provided for free.
Express has a library express-rate-limit. that can be used to rate-limit endpoints as express middleware.
Code for that would look like this:
import rateLimit from 'express-rate-limit';
export const rateLimiter = rateLimit({
windowMs: 60 * 1000, // 1 minute, in milliseconds
max: 1000,
message: 'You have exceeded the API rate limit',
headers: true,
});
router.get('/endpoint', rateLimiter, function(req, res) {
return "Woah";
})
This will result in denial of requests if the limit is exceeded.
To go into more depth, check out these articles:
https://nordicapis.com/everything-you-need-to-know-about-api-rate-limiting
Description
Currently it's possible for anyone to hit any API as fast as they want. This has been mostly fine so far because the public APIs we expose aren't really that expensive (they just retrieve info which can be cached anyway), but it'd be wise to build this in, especially as we start exposing other, more expensive operations via API keys.
Acceptance Criteria
429
with an indication of when the next request can be made (try to do this in the most standard way possible).Technical Notes