API Rate Limiting with Vercel KV and Upstash
Rate limit your Next.js application with Vercel KV and Upstash.
API Rate Limiting with Vercel KV and Upstash
This example features API Rate limiting at the edge with Vercel KV.
Demo
https://edge-functions-api-rate-limit.vercel.app
How to Use
You can choose from one of the following two methods to use this repository:
One-Click Deploy
Deploy the example using Vercel:
Clone and Deploy
Execute create-next-app
with pnpm to bootstrap the example:
pnpm create next-app --example https://github.com/vercel/examples/tree/main/edge-functions/api-rate-limit api-rate-limit
Next, create a Vercel KV database on your account and connect it to your project.
Copy the example .env.local
file shown in the dashboard with the credentials needed to connect to your Redis database. It should look similar to this:
KV_URL="redis://..."KV_REST_API_URL="https://..."KV_REST_API_TOKEN="AXx3ASQ..."KV_REST_API_READ_ONLY_TOKEN="Anx3ASQ..."
Next, run Next.js in development mode:
pnpm dev
Deploy it to the cloud with Vercel (Documentation).
API Rate Limiting with Vercel KV and Upstash
Rate limit your Next.js application with Vercel KV and Upstash.
API Rate Limiting with Vercel KV and Upstash
This example features API Rate limiting at the edge with Vercel KV.
Demo
https://edge-functions-api-rate-limit.vercel.app
How to Use
You can choose from one of the following two methods to use this repository:
One-Click Deploy
Deploy the example using Vercel:
Clone and Deploy
Execute create-next-app
with pnpm to bootstrap the example:
pnpm create next-app --example https://github.com/vercel/examples/tree/main/edge-functions/api-rate-limit api-rate-limit
Next, create a Vercel KV database on your account and connect it to your project.
Copy the example .env.local
file shown in the dashboard with the credentials needed to connect to your Redis database. It should look similar to this:
KV_URL="redis://..."KV_REST_API_URL="https://..."KV_REST_API_TOKEN="AXx3ASQ..."KV_REST_API_READ_ONLY_TOKEN="Anx3ASQ..."
Next, run Next.js in development mode:
pnpm dev
Deploy it to the cloud with Vercel (Documentation).