Ratelimiting
Bun
Ratelimiting endpoints with Bun’s http server
Prerequisites
- Created your Unkey account
- Created an Unkey root key with
ratelimit.*.create_namespace
andratelimit.*.limit
permissions.
Creating a bun server protected by Unkey
1
Create a new Bun project
First we need a bun project, so create a new directory and init bun.
2
Install
Now install the @unkey/ratelimit
package
3
Add Root Key to env
Add your root key to your .env
file
4
Modify the server
Open up the file called index.ts
and add the following code
index.ts
5
Running the server
6
Try it out
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.