Node.js based rate limiter implemented using the token bucket algorithm. It controls request traffic to prevent abuse by allowing customizable limits on user requests, thereby enhancing the performance and reliability of an application.
To run this on your local machine, first ensure you have Node installed. Link available in the Technology section.
- Clone the repository to your local machine.
git clone https://github.com/DavidLapadula/RateLimiter.git
cd ratelimiter
- Open a terminal in the root directory and run:
npm install
- Use the
config.json
to configure which endpoints are accepted by the rate limiter. Sample values are provided.
- "endpoint": a string representing the request type and endpoint
- "burst": the maximum amount of tokens that can be added to a bucket
- "sustained": how many tokens will be refilled per minute
- Open a terminal in the root directory and run:
npm start
- The
/take
endpoint will be available at port 3000 and will accept any endpoint configured in theconfig.json
- Ex:
http://localhost:3000/take?endpoint=GET /user/:id
- To test the endpoints, open a terminal in the root directory and run the command:
npm test
- The following tests will be run:
- Return the tokens remaning for an endpoint
- Consume token on an endpoint
- Ensure request rejects when out of tokens
- Induce 404 from unconfigured endpoint
- Refill tokens