Skip to content

DavidLapadula/RateLimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate Limiter

Table of contents

  1. Description
  2. Technology
  3. Usage

Description

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.

Technology

Usage

To run this on your local machine, first ensure you have Node installed. Link available in the Technology section.

  1. Clone the repository to your local machine.
git clone https://github.com/DavidLapadula/RateLimiter.git
cd ratelimiter
  1. Open a terminal in the root directory and run:
npm install
  1. 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
  1. Open a terminal in the root directory and run:
npm start
  1. The /take endpoint will be available at port 3000 and will accept any endpoint configured in the config.json
  • Ex: http://localhost:3000/take?endpoint=GET /user/:id
  1. 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