Appearance

Visual style

Mode
Theme
Accent
Advanced
Text sizeScales the whole site
16 px
Reduce motionReduce animations or match your system
Separate light and darkChoose a theme, accent and font for each
50

Technology · Backend & APIs

API development with Hono

Hono is a small, fast web framework built on Web Standard APIs. Its documentation describes routing, middleware and helpers that run unchanged on Cloudflare Workers, Deno, Bun, Node.js and other runtimes, with first-class TypeScript support and validator middleware such as Zod.

In practice

How I use Hono

I build APIs on Hono. Ekonavi's marketplace commerce API (cart, checkout, MercadoPago payments, order lifecycle, shipping) is a Hono Worker documented with OpenAPI and validated with Zod. A creator commerce platform I built uses Hono with a layered architecture: routes, use cases, domain entities, and infrastructure adapters for Razorpay, R2, Neon and Resend.

Structuring a larger Hono API

Hono provides routing and middleware and leaves architecture to you. On the creator commerce API I used four layers:

LayerResponsibilityExample
PresentationHTTP, auth middleware, request validationPOST /v1/webhooks/razorpay
ApplicationUse cases and ports (interfaces)ConfirmPaymentUseCase, IPaymentService
DomainEntities and rulesOrder.markPaid(), DownloadToken expiry
InfrastructureAdapters for external systemsRazorpay, Drizzle/Neon, R2, Resend

A request-scoped middleware injects dependencies into Hono’s context, so routes call c.get("dependencies").useCases.x instead of constructing services.

Route handlers

The webhook route on that API reads the raw body, checks that the signature header exists, hands both to a use case and returns. Verification, lookup and queueing happen in the use case, where they can be unit-tested without HTTP.

webhooksRoute.post("/razorpay", async (c) => {
  const rawBody = await c.req.text();             // raw body: needed for HMAC verification
  const signature = c.req.header("x-razorpay-signature");
  if (!signature) throw new UnauthorizedError("Missing signature header");
  await c.get("dependencies").useCases.enqueuePaymentEvent.execute(rawBody, signature);
  return c.json({ received: true });
});

Validation and errors

Requests are validated with @hono/zod-validator. Domain errors (NotFoundError, UnauthorizedError) are thrown from any layer and translated to HTTP status codes in one error-handling middleware, so status codes are consistent across every route.

Trade-offs

Where Hono shines, and where it doesn't

Strengths

  • Tiny and fast to start, which suits per-request serverless runtimes.
  • Typed routes, context and bindings with no code generation.
  • Same code runs on Workers, Node.js and Bun, so the API can move between hosts.

Limitations

  • Minimal by design: architecture, dependency injection and error conventions are yours to define.
  • Smaller ecosystem than Express or NestJS for niche integrations.

Sources

Official documentation

General descriptions on this page are based on the official documentation linked below. Experience notes are my own.

FAQ

Hono questions

Why Hono instead of Express?

Hono is built on Web Standard Request and Response, so it runs natively on Cloudflare Workers and other edge runtimes, starts quickly and is fully typed. Express is built around Node's HTTP module and is a poor fit for Workers.

How do you structure a larger Hono API?

In layers. Routes handle HTTP and validation only. Use cases hold business rules. Domain entities enforce invariants. Infrastructure adapters wrap databases, payment providers, storage and email behind interfaces, so a provider can be swapped or mocked in tests without touching business logic.

How do you validate requests in a Hono API?

With the Zod validator middleware: each route declares a schema for its body, query or params, invalid requests are rejected with a 400 before the handler runs, and the handler receives fully typed, validated data. Error responses come from one shared error-handling middleware.

Need a Hono developer?

If your project needs Hono, send a short description of what you're building and where it's stuck. I'll reply with how I'd approach it.