This is a simple rate limiter library that I made in a single day for educational purposes, so it's not recommended to use it on production environments.
Instructions
Copy the file .env.sample and paste it on your project's root directory, and then name it .env.
Run docker compose up in the project's root directory
If you have VS Code installed and have the REST Client extension enabled, you can use the api.http file to send requests, or you can use any other REST client like Postman, or any other tool (e.g.: Apache ab CLI).
Environment Variables
Name
Accepts
Default Value
Description
RATE_LIMITER_IP_ADDRESS_MAX_REQUESTS
number
2
Max requests per IP address
RATE_LIMITER_IP_ADDRESS_LIMIT_IN_SECONDS
number
1
IP Address limit duration in seconds (the amount of time the max requests are allowed in)
RATE_LIMITER_IP_ADDRESS_BLOCK_IN_SECONDS
number
5
IP Address block duration in seconds (the amount of time the IP address is blocked for after exceeding the max requests)
RATE_LIMITER_TOKENS_HEADER_KEY
string
API_KEY
The requests' Header key to use for the tokens
RATE_LIMITER_TOKENS_CONFIG_TUPLE
string
A list of tokens separated by a comma and their respective max requests, limit and block durations in seconds separated by a colon