Back to Templates

Hono Ratelimit Starter for Cloudflare Workers

Simple hono and cloudflare workers api with rate limiting by unkey

Written by
Devansh-Baghel
Framework
Hono
Language
Typescript
Simple hono and cloudflare workers api with rate limiting by unkey

Hono Unkey Ratelimit Starter for Cloudflare Workers

This is a minimal starter template showcasing how to use Unkey for rate limiting in a web server built with the Hono framework, deployed to Cloudflare Workers.

Features

  • Rate Limiting: Implements Unkey's rate-limiting capabilities to control requests based on unique identifiers like IP addresses or custom headers.
  • Hono Framework: A lightweight, ultrafast web framework for the Edge (Cloudflare Workers, Deno Deploy, etc.).
  • Cloudflare Workers: Deploy your application to Cloudflare’s global edge network for fast, scalable performance.

Setup and Installation

1. Clone the repository

1git clone https://github.com/Devansh-Baghel/hono-unkey-ratelimit-starter.git
2cd hono-unkey-ratelimit-starter

2. Configure environment variables

Copy the .dev.vars.example file to .dev.vars file in the root directory and add your Unkey root key:

1cp .dev.vars.example .dev.vars

3. Install dependencies and start your server

Install all dependencies from package.json:

1npm install

Now start your development server:

1npm run dev

Server will now be running at http://localhost:8787

4. Deploy your app to production (optional)

You will need a cloudflare account for this

1npm run deploy

Usage

Public Route

GET /: A simple welcome message.

Protected Route (Rate Limited)

GET /secret: This route is rate-limited by Unkey. After exceeding the limit (2 requests in 30 seconds), it returns a 429 Too Many Requests response.

License

This project is licensed under the MIT License.

Protect your API.
Start today.

150,000 requests per month. No CC required.