Why Hono
Hono is a lightweight web framework built for edge runtimes — Cloudflare Workers, Deno, Bun, Vercel Edge, AWS Lambda. It runs everywhere with the same code and is blazing fast (~12K req/sec on Workers).
Install
npm create hono@latest my-app
cd my-app
npm install
npm run dev
Basic App
import { Hono } from 'hono';
const app = new Hono();
app.get('/', (c) => c.text('Hello Hono!'));
app.get('/api/users/:id', async (c) => {
const id = c.req.param('id');
const user = await getUser(id);
return c.json(user);
});
app.post('/api/users', async (c) => {
const body = await c.req.json();
const user = await createUser(body);
return c.json(user, 201);
});
export default app;
Middleware
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { logger } from 'hono/logger';
import { bearerAuth } from 'hono/bearer-auth';
import { zValidator } from '@hono/zod-validator';
import { z } from 'zod';
const app = new Hono();
app.use('*', logger());
app.use('/api/*', cors());
app.use('/admin/*', bearerAuth({ token: 'secret' }));
app.post('/api/users',
zValidator('json', z.object({
name: z.string().min(2),
email: z.string().email(),
})),
async (c) => {
const data = c.req.valid('json');
return c.json({ user: data });
}
);
Deploy Everywhere
// Same code runs on:
// - Cloudflare Workers
// - Deno Deploy
// - Bun
// - AWS Lambda
// - Vercel Edge
// - Node.js
export default app;
RPC Mode (Type-Safe Client)
// Server
const routes = app.get('/api/posts', async (c) => {
return c.json(await getPosts());
});
export type AppType = typeof routes;
// Client
import { hc } from 'hono/client';
import type { AppType } from './server';
const client = hc<AppType>('http://localhost:3000');
const posts = await client.api.posts.$get();
Key Features
- Ultrafast — one of the fastest JS frameworks
- Multi-runtime — Workers, Deno, Bun, Node, Lambda
- Tiny — ~14KB, zero dependencies
- Middleware — auth, cors, logger, compress, JWT
- Validator — Zod integration built-in
- RPC — type-safe client like tRPC
Resources
Need to extract API data, edge runtime metrics, or web framework configs? Check out my Apify tools or email spinov001@gmail.com for custom solutions.
Top comments (0)