Ratelimiting
Next.js
Ratelimiting endpoints with Next.js
Prerequisites
- Created your Unkey account
- Created an Unkey root key with
ratelimit.*.create_namespace
andratelimit.*.limit
permissions.
1
Create Next.js Application
Run the following command to init your Next.js project
2
Install
Now install the @unkey/ratelimit
package
3
Add Root Key to env
Add your root key to your .env
file
4
Creating a protected route
Create a new route and add the following code
/app/protected/route.ts
5
Running it
6
Try it out
Go to https://app.unkey.com and create a new key. Then verify it with our new server:
You will need to curl a few times to see the ratelimiting error. Once you do, you, you will need to wait to perform the action again.
What is next?
Now that you’ve seen the power of Unkey, check out some resources below to continue your journey.