This Nuxt.js application implements a robust rate-limiting solution for API routes using the Unkey Rate Limit API. By leveraging Unkey's powerful rate-limiting capabilities, this app ensures efficient control over API requests, preventing abuse and ensuring fair usage among clients. With minimal configuration, you can safeguard your API endpoints while maintaining optimal performance.
- Seamless Integration: Easily implement rate limiting in Nuxt.js with minimal setup.
- Dynamic Controls: Configure limits based on user roles or API keys for tailored access.
- Enhanced Security: Protect your APIs from abuse and ensure optimal performance.
- E-commerce: Prevent excessive requests during peak sales events.
- Public APIs: Safeguard against abuse by limiting user requests.
- Internal Tools: Manage resource consumption for internal applications effectively.
- Navigate to Unkey Root Keys and click "Create New Root Key".
- Name your root key.
- Select the following workspace permissions:
create_keyread_keyencrypt_keydecrypt_key
- Click "Create" and save your root key securely.
- Go to Unkey Ratelimits and click "Create New Namespace".
- Enter a name for the namespace.
- Click "Create".
-
Clone the repository to your local machine:
git clone [email protected]:unrenamed/unkey-nuxt-ratelimit cd unkey-nuxt-ratelimit
-
Create a
.envfile in the root directory and populate it with the following environment variables:UNKEY_ROOT_KEY=your-unkey-root-key UNKEY_NAMESPACE=your-unkey-namespace
Ensure you replace
your-unkey-*with your actual Unkey credentials. -
Start the server:
pnpm dev
The server will start and listen on the
3000port. -
To test the API route, use the command:
curl http://localhost:3000/api/hello-world -H "x-forwarded-for: <any IP address>"and repeatedly execute it to trigger a 429 Too Many Requests response when the rate limit is exceeded.