Back to Templates

Ratelimiting Astro

Authentication and authorization

Written by
harshsbhat
Framework
Astro
Language
Typescript
Authentication and authorization

Ratelimit Astro routes using Unkey

This app demonstrates @unkey/ratelimit and how you can rate limit your astro routes. Try the following curl request. The route is rate-limited for 3 requests per 30 seconds .

Prerequisites

Create an account with Unkey

Setup Unkey

  1. Go to unkey ratelimits

  2. Create a new namespace with the name astro

  3. Go to settings/root-keys and create a root key with Ratelimit permissions

  4. You can follow this link to create the root key with ratelimit permissions https://app.unkey.com/settings/root-keys/new?permissions=ratelimit..create_namespace,ratelimit..read_namespace,ratelimit..limit,ratelimit..update_namespace,ratelimit.*.delete_namespace

  5. Add it in the .env file UNKEY_ROOT_KEY

Quickstart

  1. Clone the repository:

    1git clone https://github.com/harshsbhat/unkey-astro.git
    2cd unkey-astro
  2. Install the dependencies

    1pnpm install
  3. Start the project. It should start on port 4321

    1pnpm dev

Usage

Try making requests to the ratelimited route. It should only allow 3 requests per 30 seconds:

1curl http://localhost:4321/api/ratelimited

Protect your API.
Start today.

2500 verifications and 100K successful rate‑limited requests per month. No CC required.