Hono — Ultrafast Web Framework
You are an expert in Hono, the ultrafast web framework for the edge. You help developers build APIs and web applications that run on Cloudflare Workers, Deno, Bun, Node.js, AWS Lambda, and Vercel Edge — with a tiny footprint (~14KB), middleware ecosystem, JSX support, RPC client, and Web Standards API compatibility that makes code truly portable across runtimes.
Core Capabilities
API Routes
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import { jwt } from "hono/jwt";
import { zValidator } from "@hono/zod-validator";
import { z } from "zod";
const app = new Hono();
// Middleware
app.use("*", logger());
app.use("/api/*", cors({ origin: ["https://myapp.com"], credentials: true }));
app.use("/api/protected/*", jwt({ secret: process.env.JWT_SECRET! }));
// Typed routes with Zod validation
const createUserSchema = z.object({
name: z.string().min(1),
email: z.string().email(),
role: z.enum(["user", "admin"]).default("user"),
});
app.get("/api/users", async (c) => {
const { page, limit } = c.req.query();
const users = await db.users.findMany({
skip: ((+page || 1) - 1) * (+limit || 20),
take: +limit || 20,
});
return c.json({ data: users });
});
app.post("/api/users", zValidator("json", createUserSchema), async (c) => {
const body = c.req.valid("json"); // Typed as { name: string, email: string, role: "user" | "admin" }
const user = await db.users.create({ data: body });
return c.json(user, 201);
});
app.get("/api/users/:id", async (c) => {
const id = c.req.param("id");
const user = await db.users.findUnique({ where: { id } });
if (!user) return c.json({ error: "Not found" }, 404);
return c.json(user);
});
// Protected route
app.get("/api/protected/me", (c) => {
const payload = c.get("jwtPayload");
return c.json({ userId: payload.sub });
});
export default app;
RPC Client (Type-Safe)
// server.ts — Export typed routes
const routes = app
.get("/api/users", ...)
.post("/api/users", ...);
export type AppType = typeof routes;
// client.ts — Type-safe client (like tRPC but for REST)
import { hc } from "hono/client";
import type { AppType } from "./server";
const client = hc<AppType>("https://api.myapp.com");
const users = await client.api.users.$get();
const json = await users.json(); // Typed as User[]
const newUser = await client.api.users.$post({
json: { name: "Alice", email: "alice@example.com" }, // Type-checked!
});
JSX and HTML
import { Hono } from "hono";
import { html } from "hono/html";
const app = new Hono();
app.get("/", (c) => {
return c.html(
<html>
<body>
<h1>Hello from Hono!</h1>
<p>Running on {c.runtime}</p>
</body>
</html>
);
});
// Streaming
app.get("/stream", (c) => {
return c.streamText(async (stream) => {
for (const word of "Hello World from Hono!".split(" ")) {
await stream.write(word + " ");
await stream.sleep(100);
}
});
});
Installation
npm create hono@latest my-app
# Choose: cloudflare-workers | nodejs | bun | deno | vercel | aws-lambda
cd my-app && npm install
npm run dev
Best Practices
- Web Standards — Uses
Request/Response API; code runs on any runtime without changes
- Zod validation — Use
@hono/zod-validator for type-safe request validation; compile + runtime safety
- RPC client — Use
hc<AppType>() for type-safe client; catches API contract mismatches at compile time
- Middleware — Rich ecosystem: cors, jwt, logger, compress, cache, rate-limit, OpenAPI
- Edge-first — 14KB bundle; runs on Cloudflare Workers with <1ms cold start
- Multi-runtime — Same code deploys to Workers, Bun, Deno, Node, Lambda; switch with one config change
- JSX support — Built-in JSX for server-rendered HTML; no React needed for simple pages
- Streaming —
c.streamText() and c.stream() for SSE, chunked responses, AI streaming
1---2name: hono3description: You are an expert in Hono, the ultrafast web framework for the edge. You help developers build APIs and web applications that run on Cloudflare Workers, Deno, Bun, Node.js, AWS Lambda, and Vercel Edge — with a tiny footprint (~14KB), middleware ecosystem, JSX support, RPC client, and Web Standards API compatibility that makes code truly portable across runtimes.4license: Apache-2.05---67# Hono — Ultrafast Web Framework89You are an expert in Hono, the ultrafast web framework for the edge. You help developers build APIs and web applications that run on Cloudflare Workers, Deno, Bun, Node.js, AWS Lambda, and Vercel Edge — with a tiny footprint (~14KB), middleware ecosystem, JSX support, RPC client, and Web Standards API compatibility that makes code truly portable across runtimes.1011## Core Capabilities1213### API Routes1415```typescript16import { Hono } from "hono";17import { cors } from "hono/cors";18import { logger } from "hono/logger";19import { jwt } from "hono/jwt";20import { zValidator } from "@hono/zod-validator";21import { z } from "zod";2223const app = new Hono();2425// Middleware26app.use("*", logger());27app.use("/api/*", cors({ origin: ["https://myapp.com"], credentials: true }));28app.use("/api/protected/*", jwt({ secret: process.env.JWT_SECRET! }));2930// Typed routes with Zod validation31const createUserSchema = z.object({32 name: z.string().min(1),33 email: z.string().email(),34 role: z.enum(["user", "admin"]).default("user"),35});3637app.get("/api/users", async (c) => {38 const { page, limit } = c.req.query();39 const users = await db.users.findMany({40 skip: ((+page || 1) - 1) * (+limit || 20),41 take: +limit || 20,42 });43 return c.json({ data: users });44});4546app.post("/api/users", zValidator("json", createUserSchema), async (c) => {47 const body = c.req.valid("json"); // Typed as { name: string, email: string, role: "user" | "admin" }48 const user = await db.users.create({ data: body });49 return c.json(user, 201);50});5152app.get("/api/users/:id", async (c) => {53 const id = c.req.param("id");54 const user = await db.users.findUnique({ where: { id } });55 if (!user) return c.json({ error: "Not found" }, 404);56 return c.json(user);57});5859// Protected route60app.get("/api/protected/me", (c) => {61 const payload = c.get("jwtPayload");62 return c.json({ userId: payload.sub });63});6465export default app;66```6768### RPC Client (Type-Safe)6970```typescript71// server.ts — Export typed routes72const routes = app73 .get("/api/users", ...)74 .post("/api/users", ...);7576export type AppType = typeof routes;7778// client.ts — Type-safe client (like tRPC but for REST)79import { hc } from "hono/client";80import type { AppType } from "./server";8182const client = hc<AppType>("https://api.myapp.com");8384const users = await client.api.users.$get();85const json = await users.json(); // Typed as User[]8687const newUser = await client.api.users.$post({88 json: { name: "Alice", email: "alice@example.com" }, // Type-checked!89});90```9192### JSX and HTML9394```tsx95import { Hono } from "hono";96import { html } from "hono/html";9798const app = new Hono();99100app.get("/", (c) => {101 return c.html(102 <html>103 <body>104 <h1>Hello from Hono!</h1>105 <p>Running on {c.runtime}</p>106 </body>107 </html>108 );109});110111// Streaming112app.get("/stream", (c) => {113 return c.streamText(async (stream) => {114 for (const word of "Hello World from Hono!".split(" ")) {115 await stream.write(word + " ");116 await stream.sleep(100);117 }118 });119});120```121122## Installation123124```bash125npm create hono@latest my-app126# Choose: cloudflare-workers | nodejs | bun | deno | vercel | aws-lambda127cd my-app && npm install128npm run dev129```130131## Best Practices1321331. **Web Standards** — Uses `Request`/`Response` API; code runs on any runtime without changes1342. **Zod validation** — Use `@hono/zod-validator` for type-safe request validation; compile + runtime safety1353. **RPC client** — Use `hc<AppType>()` for type-safe client; catches API contract mismatches at compile time1364. **Middleware** — Rich ecosystem: cors, jwt, logger, compress, cache, rate-limit, OpenAPI1375. **Edge-first** — 14KB bundle; runs on Cloudflare Workers with <1ms cold start1386. **Multi-runtime** — Same code deploys to Workers, Bun, Deno, Node, Lambda; switch with one config change1397. **JSX support** — Built-in JSX for server-rendered HTML; no React needed for simple pages1408. **Streaming** — `c.streamText()` and `c.stream()` for SSE, chunked responses, AI streaming