DocsWeb development

Build APIs with Hono

Create a testable Hono REST API on Deno that can move across runtimes

Hono has a small API, builds on Web standards, and lets business routes move across runtimes. Start with its official Deno template:

deno init --npm hono --template=deno my-api
cd my-api
deno task start

Minimal service

import { Hono } from "hono";

const app = new Hono();

app.get("/health", (c) => c.json({ ok: true }));
app.get("/users/:id", (c) => c.json({ id: c.req.param("id") }));

Deno.serve({ port: 8000 }, app.fetch);

Test without listening

import { assertEquals } from "@std/assert";

Deno.test("GET /health", async () => {
  const response = await app.request("http://localhost/health");
  assertEquals(response.status, 200);
  assertEquals(await response.json(), { ok: true });
});

npm or JSR

Hono ships on npm and JSR. When third-party middleware participates in type inference, keep Hono core and middleware on the same registry to avoid duplicate type instances. Static-file helpers come from hono/deno and need corresponding file-read permission.

A production API should also add schema validation, consistent error mapping, a CORS allowlist, body limits, timeouts, request IDs, and structured logs.

Official references: Hono on Deno and Hono middleware.

Type to search all documentation.