Back to Templates

Ratelimiting in AdonisJS apps

Dynami IP based ratelimiting.

Written by
Ionfinisher
Framework
AdonisJS
Language
Typescript
Dynami IP based ratelimiting.

AdonisJS Ratelimit Starter

Overview

This a starter AdonisJS application which implements rate limiting with Unkey Ratelimit feature. There are two endpoints, a public one and a protected one that is limited to two request per 30 seconds.

Features

  • Public endpoint accessible without limitation
  • Protected endpoint ratelimited to two requests per 30 seconds

Quickstart

Set up the example

  1. Clone the repository:

    1git clone https://github.com/Ionfinisher/unkey-adonisjs-ratelimit.git
  2. Navigate to the project directory:

    1cd <project-directory>
  3. Install the dependencies:

    1npm install
  4. Change the .env.example to .env file and add the following:

    1UNKEY_ROOT_KEY=your-root-key

Get the root key from https://app.unkey.com/settings/root-keys

  1. Start the server

    1cd to the root of the project directory
    2node ace serve --watch
  2. curl the unprotected route

    1 curl http://127.0.0.1:3333/api/v1/public

    It should return Heeyaaa!! Touchdown to the public and unlimited endpoint!!

  3. curl the protected route

    1 curl http://127.0.0.1:3333/api/v1/protected

    It should return Woohoo!! Touchdown to the protected endpoint!! But after two requests in 30 seconds it should return WoW! Try again later.

License

This project is licensed under the MIT License.

Further information

For further information, go to unkey.

Protect your API.
Start today.

2500 verifications and 100K successful rate‑limited requests per month. No CC required.