Rate-Limiter Middleware Function
Implement the middleware function to limit the API calls made from an IP address in a defined window.
We'll cover the following...
We’ve learned about middleware functions and some of their use cases. Since our rate-limiting function can be used by multiple APIs in our app, we’ll create it as middleware. As discussed earlier, we’ll keep our middleware function to be configurable in terms of allowed API hits and the windows in seconds for different APIs. So, we’ll create a function named rateLimiter()
that accepts three parameters: the time in seconds denoting our window, the number of allowed hits from an IP address in that window, and a simple message to differentiate all the different API endpoint calls.
Now, to make this ...