Hono is an ultrafast web framework that runs everywhere — Cloudflare Workers, Deno, Bun, Node.js, AWS Lambda. Its middleware system lets you compose powerful APIs in minutes.
Why Hono?
- Ultra-fast: 3x faster than Express on benchmarks
- Multi-runtime: Same code on Workers, Deno, Bun, Node
- Type-safe: Full TypeScript with RPC client
- Tiny: Core is 14KB
- Rich middleware: CORS, JWT, rate limiting, OpenAPI built-in
Quick Setup
npm create hono@latest my-api
cd my-api && npm run dev
Basic API
import { Hono } from 'hono';
const app = new Hono();
app.get('/api/posts', async (c) => {
const posts = await db.post.findMany();
return c.json(posts);
});
app.post('/api/posts', async (c) => {
const body = await c.req.json();
const post = await db.post.create({ data: body });
return c.json(post, 201);
});
export default app;
Built-in Middleware
import { cors } from 'hono/cors';
import { jwt } from 'hono/jwt';
import { logger } from 'hono/logger';
import { rateLimiter } from 'hono/rate-limiter';
app.use('*', logger());
app.use('/api/*', cors({ origin: 'https://myapp.com' }));
app.use('/api/protected/*', jwt({ secret: process.env.JWT_SECRET }));
Custom Middleware
import { createMiddleware } from 'hono/factory';
const timing = createMiddleware(async (c, next) => {
const start = Date.now();
await next();
c.header('X-Response-Time', `${Date.now() - start}ms`);
});
app.use('*', timing);
Route Groups
const api = new Hono();
api.get('/users', (c) => c.json(users));
api.get('/users/:id', (c) => c.json(users[c.req.param('id')]));
app.route('/api/v1', api);
Zod Validation
import { zValidator } from '@hono/zod-validator';
import { z } from 'zod';
const schema = z.object({
title: z.string().min(1),
body: z.string().min(10),
});
app.post('/api/posts', zValidator('json', schema), async (c) => {
const data = c.req.valid('json');
const post = await db.post.create({ data });
return c.json(post, 201);
});
RPC Client (Type-Safe Fetch)
// Server
const routes = app.get('/api/posts', async (c) => {
return c.json(await db.post.findMany());
});
export type AppType = typeof routes;
// Client
import { hc } from 'hono/client';
import type { AppType } from './server';
const client = hc<AppType>('https://api.example.com');
const posts = await client.api.posts.$get();
// Full type inference!
Real-World Use Case
A startup migrated from Express to Hono on Cloudflare Workers. Response times went from 200ms to 12ms, and cold starts disappeared. Their API now handles 100K requests/second on the free tier.
Need to automate data collection? Check out my Apify actors for ready-made scrapers, or email spinov001@gmail.com for custom solutions.
Top comments (0)