“Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform

As a developer, one of the most rewarding experiences is bringing an idea to life. I recently embarked on a project called devTinder, a platform designed to connect developers and tech enthusiasts for collaboration and networking. As I prepared for the…


This content originally appeared on DEV Community and was authored by Manish Kr Prasad

As a developer, one of the most rewarding experiences is bringing an idea to life. I recently embarked on a project called devTinder, a platform designed to connect developers and tech enthusiasts for collaboration and networking. As I prepared for the deployment phase (only backend), I realized that ensuring fair usage of resources was paramount to the success of my project. I wanted to protect my application from potential misuse and abuse, so I decided to implement rate limiting using Unkey.

Why Unkey & How I came to know about Unkey?

My journey with Unkey began during the ongoing Hacktoberfest 2024, an event that celebrates open-source contributions and encourages developers to collaborate on exciting projects. As I learned more about its capabilities, I realized that Unkey also offered exactly what I needed for devTinder ie rate-limiting. Now let's answer the question why Unkey:

  • Open Source:
    Unkey is built on an open-source model, allowing developers to contribute, customize, and adapt the tool to fit their specific needs. This fosters a collaborative community that continuously improves the platform.

  • Protection Against DoS Attacks:
    With robust rate limiting features and simple to integrate, Unkey can provides essential protection against Denial of Service (DoS) attacks. It prevent excessive or abusive use of a resource and to ensure that the resource is available to all legitimate users.

  • No Credit Card Required:
    Getting started with Unkey is hassle-free—there’s no need to provide credit card information. This allows developers to explore the platform without any financial commitments, making it accessible for projects of all sizes.

Using Unkey rate-limiting feature

  1. Go to https://app.unkey.com/settings/root-keys/new

  2. Give a name and in the Workspace section make sure to check all options of Ratelimit. Then click on Create new Key.

  3. Copy your key, it will be shown as Your API key

If you feel lost, you can follow their well documented doc.
Now copy the above key in your .env file and make sure to keep the key as UNKEY_ROOT_KEY.

eg. UNKEY_ROOT_KEY="unkey_************************"

Now we need to create a file rateLimit.ts (filename is not fixed)
to store the ratelimit configuration.

rateLimitConfig

Final step

I want to protect my routes /signup and /login from being misuse, so I will protect this two routes. Below is the code

signup

login

Note: you only need those 4-5 line to get rate-limiting in your app. Yes, it's that easy and it works like magic.

Demo:

Conclusion:

If you’re considering launching your own application, I highly recommend looking into rate limiting as a means of protecting your resources and ensuring fair usage. Tools like Unkey make it easier than ever to implement these features, allowing you to focus on what you do best—building great software!


This content originally appeared on DEV Community and was authored by Manish Kr Prasad


Print Share Comment Cite Upload Translate Updates
APA

Manish Kr Prasad | Sciencx (2024-10-24T20:58:38+00:00) “Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform. Retrieved from https://www.scien.cx/2024/10/24/rate-limiting-simplified-my-journey-with-unkey-the-open-source-api-management-platform/

MLA
" » “Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform." Manish Kr Prasad | Sciencx - Thursday October 24, 2024, https://www.scien.cx/2024/10/24/rate-limiting-simplified-my-journey-with-unkey-the-open-source-api-management-platform/
HARVARD
Manish Kr Prasad | Sciencx Thursday October 24, 2024 » “Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform., viewed ,<https://www.scien.cx/2024/10/24/rate-limiting-simplified-my-journey-with-unkey-the-open-source-api-management-platform/>
VANCOUVER
Manish Kr Prasad | Sciencx - » “Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/24/rate-limiting-simplified-my-journey-with-unkey-the-open-source-api-management-platform/
CHICAGO
" » “Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform." Manish Kr Prasad | Sciencx - Accessed . https://www.scien.cx/2024/10/24/rate-limiting-simplified-my-journey-with-unkey-the-open-source-api-management-platform/
IEEE
" » “Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform." Manish Kr Prasad | Sciencx [Online]. Available: https://www.scien.cx/2024/10/24/rate-limiting-simplified-my-journey-with-unkey-the-open-source-api-management-platform/. [Accessed: ]
rf:citation
» “Rate Limiting, Simplified”: My Journey with Unkey, the Open-Source API Management Platform | Manish Kr Prasad | Sciencx | https://www.scien.cx/2024/10/24/rate-limiting-simplified-my-journey-with-unkey-the-open-source-api-management-platform/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.