Coder Social home page Coder Social logo

ratelimiter's Introduction

Rate Limiter

Table of Contents

Project-Overview

This repo exemplifies API rate limiting, using the token bucket algorithm. the rate limitter implementation can be found in middlewares/rateLimiter/limitRate

Features

  • Allows for rate limit specification
  • Allows for limit time range customisation
  • provides hard throttling when rate limit exceeded
  • Extendable

Environment Variables

To run this project, you will need to add the following environment variables to your .env file if you choose to run locally

  • Required
    • DATABASE_URL=string (databaseUrl)
    • SECRET=string (Jwt secret)

Test

  • How To:

    • Automated test can be run using yarn test (this will require env variables)
    • The rate limiting functionality is tested by making recurrent request to the endpoints. It has been configured such that the API allows a max of 10 requests per client within a duration of 1 mminute. After 10 successful requests, Error 429 is retuned. Also, the rate limit information is returned in the headers.
  • Local env test [ Downlad Postman Collection ]

    • clone repo
    • create a .env file and supply the env variables in .env.sample
    • run yarn start
    • make request to:
      • localhost:5000/api/v1/auth/signup
      • localhost:5000/api/v1/auth/signup
      • localhost:5000/api/v1/mail Run in Postman
  • Remote Ephemeral server test [ Downlad Postman Collection ]

    • Downlad Postman Collection or click run in postman below
    • make request to:
      • https://ratelimiter-production.up.railway.app/api/v1/auth/signup
      • https://ratelimiter-production.up.railway.app/api/v1/auth/signup
      • https://ratelimiter-production.up.railway.app/api/v1/mail Run in Postman

Note: the postman requests prepended with the "Local" keyword are to be used for local testing only

Screenshot

Unthrottled maiden request headers

image

Throttled request headers

image

This File was generated by md-generator

ratelimiter's People

Contributors

oluwasegun-aa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.