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: >-4 You are an expert in Hono, the ultrafast web framework for the edge. You5 help developers build APIs and web applications that run on Cloudflare6 Workers, Deno, Bun, Node.js, AWS Lambda, and Vercel Edge — with a tiny7 footprint (~14KB), middleware ecosystem, JSX support, RPC client, and Web8 Standards API compatibility that makes code truly portable across runtimes.9license: Apache-2.010compatibility: ''11metadata:12 source: https://skillmd.com/skills/eliferjunior/hono13 author: terminal-skills14 version: 1.0.015 category: Backend Development16 tags:17 - web-framework18 - edge19 - cloudflare20 - bun21 - deno22 - fast23 - typescript24---2526# Hono — Ultrafast Web Framework2728You 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.2930## Core Capabilities3132### API Routes3334```typescript35import { Hono } from "hono";36import { cors } from "hono/cors";37import { logger } from "hono/logger";38import { jwt } from "hono/jwt";39import { zValidator } from "@hono/zod-validator";40import { z } from "zod";4142const app = new Hono();4344// Middleware45app.use("*", logger());46app.use("/api/*", cors({ origin: ["https://myapp.com"], credentials: true }));47app.use("/api/protected/*", jwt({ secret: process.env.JWT_SECRET! }));4849// Typed routes with Zod validation50const createUserSchema = z.object({51 name: z.string().min(1),52 email: z.string().email(),53 role: z.enum(["user", "admin"]).default("user"),54});5556app.get("/api/users", async (c) => {57 const { page, limit } = c.req.query();58 const users = await db.users.findMany({59 skip: ((+page || 1) - 1) * (+limit || 20),60 take: +limit || 20,61 });62 return c.json({ data: users });63});6465app.post("/api/users", zValidator("json", createUserSchema), async (c) => {66 const body = c.req.valid("json"); // Typed as { name: string, email: string, role: "user" | "admin" }67 const user = await db.users.create({ data: body });68 return c.json(user, 201);69});7071app.get("/api/users/:id", async (c) => {72 const id = c.req.param("id");73 const user = await db.users.findUnique({ where: { id } });74 if (!user) return c.json({ error: "Not found" }, 404);75 return c.json(user);76});7778// Protected route79app.get("/api/protected/me", (c) => {80 const payload = c.get("jwtPayload");81 return c.json({ userId: payload.sub });82});8384export default app;85```8687### RPC Client (Type-Safe)8889```typescript90// server.ts — Export typed routes91const routes = app92 .get("/api/users", ...)93 .post("/api/users", ...);9495export type AppType = typeof routes;9697// client.ts — Type-safe client (like tRPC but for REST)98import { hc } from "hono/client";99import type { AppType } from "./server";100101const client = hc<AppType>("https://api.myapp.com");102103const users = await client.api.users.$get();104const json = await users.json(); // Typed as User[]105106const newUser = await client.api.users.$post({107 json: { name: "Alice", email: "alice@example.com" }, // Type-checked!108});109```110111### JSX and HTML112113```tsx114import { Hono } from "hono";115import { html } from "hono/html";116117const app = new Hono();118119app.get("/", (c) => {120 return c.html(121 <html>122 <body>123 <h1>Hello from Hono!</h1>124 <p>Running on {c.runtime}</p>125 </body>126 </html>127 );128});129130// Streaming131app.get("/stream", (c) => {132 return c.streamText(async (stream) => {133 for (const word of "Hello World from Hono!".split(" ")) {134 await stream.write(word + " ");135 await stream.sleep(100);136 }137 });138});139```140141## Installation142143```bash144npm create hono@latest my-app145# Choose: cloudflare-workers | nodejs | bun | deno | vercel | aws-lambda146cd my-app && npm install147npm run dev148```149150## Best Practices1511521. **Web Standards** — Uses `Request`/`Response` API; code runs on any runtime without changes1532. **Zod validation** — Use `@hono/zod-validator` for type-safe request validation; compile + runtime safety1543. **RPC client** — Use `hc<AppType>()` for type-safe client; catches API contract mismatches at compile time1554. **Middleware** — Rich ecosystem: cors, jwt, logger, compress, cache, rate-limit, OpenAPI1565. **Edge-first** — 14KB bundle; runs on Cloudflare Workers with <1ms cold start1576. **Multi-runtime** — Same code deploys to Workers, Bun, Deno, Node, Lambda; switch with one config change1587. **JSX support** — Built-in JSX for server-rendered HTML; no React needed for simple pages1598. **Streaming** — `c.streamText()` and `c.stream()` for SSE, chunked responses, AI streaming