How to implement http middleware using RateLimiter effect?
first of all, effect provides very efficient RateLimiter, and I'd like to use it to implement rate limit middleware.
As a ratelimit key, we can use some specific request header value, (e.g. req.headers['x-api-key']).. There are some problems with this implementation that
- ratelimiter for specific api key should not be reset for every request
- we should be able to get the remaining ratelimit amounts to expose in the response header, but I don't see a way to get the "remaining limits" in the current RateLimiter implementation.
Can you help with this? Any example code or high-level guidance would be much appreciated
As a ratelimit key, we can use some specific request header value, (e.g. req.headers['x-api-key']).. There are some problems with this implementation that
- ratelimiter for specific api key should not be reset for every request
- we should be able to get the remaining ratelimit amounts to expose in the response header, but I don't see a way to get the "remaining limits" in the current RateLimiter implementation.
Can you help with this? Any example code or high-level guidance would be much appreciated
GitHub
An ecosystem of tools to build robust applications in TypeScript. - Effect-TS/effect
