PAS7 Studio
Illustration of Bun.js, Hono, OpenAPI, and Scalar
Technology27 Aug 2026·3 min read·Updated 27 Aug 2026

Bun.js + Hono + OpenAPI: a documented API with Scalar

Build a lightweight Bun.js API with Hono, Zod validation, OpenAPI contracts, and interactive Scalar documentation.

TypeScript developersPublic API teamsFrontend and backend teams

Hono routes requests on Bun, Zod validates payloads, OpenAPI describes the contract, and Scalar renders interactive documentation. Keeping these layers aligned prevents frontend and backend drift.

One contract serves runtime, humans, and client generators.
Documentation changes together with route code.
Hono stays small and works well for edge-style APIs.
Xin

The contract architecture

An executable schema is more reliable than a Markdown document that slowly becomes outdated.

Hono

A fast router based on Web Request and Response APIs.

Zod

Validates params, query, and JSON before a handler runs.

OpenAPI

Formalizes endpoints, responses, errors, and security schemes.

Scalar

Provides an interactive API reference for teams and integrators.

One route contract powers the request, validation, OpenAPI JSON, and Scalar documentation.

Section architecture screenshot

Step 1: install and create the server

01

Install packages

BASH
bun init
bun add hono @hono/zod-openapi zod @scalar/hono-api-reference
02

Create an OpenAPI app

TS
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
const app = new OpenAPIHono();
const task = z.object({ id: z.string(), title: z.string(), done: z.boolean() });
const route = createRoute({ method: "get", path: "/tasks/{id}", request: { params: z.object({ id: z.string().uuid() }) }, responses: { 200: { content: { "application/json": { schema: task } }, description: "A task" } } });
app.openapi(route, (c) => c.json({ id: c.req.valid("param").id, title: "Read docs", done: false }));
03

Expose documentation

TS
app.doc("/openapi.json", { openapi: "3.1.0", info: { title: "Tasks API", version: "1.0.0" } });
app.get("/docs", apiReference({ spec: { url: "/openapi.json" } }));
export default { port: Number(Bun.env.PORT ?? 3000), fetch: app.fetch };

Run bun run src/index.ts. Open /docs for the UI and /openapi.json for the contract.

Step 2: validate bodies and errors

Document more than the happy path. Stable 400, 404, and 500 schemas are part of a useful API contract.

TS
const createTask = createRoute({ method: "post", path: "/tasks", request: { body: { content: { "application/json": { schema: z.object({ title: z.string().trim().min(1).max(120) }) } } } }, responses: { 201: { content: { "application/json": { schema: task } }, description: "Created" }, 422: { content: { "application/json": { schema: z.object({ error: z.string() }) } }, description: "Validation error" } } });
app.openapi(createTask, async (c) => { const body = c.req.valid("json"); return c.json({ id: crypto.randomUUID(), title: body.title, done: false }, 201); });

Step 3: use contract-first clients

Frontend

Generate a fetch client or types from /openapi.json instead of duplicating DTOs.

Public docs

Protect /docs with auth when the API is private; documentation can reveal internal endpoints.

Versioning

Move breaking changes to /v2 or a new document instead of silently changing required fields.

Tests and CI

01

Check the OpenAPI JSON

BASH
curl http://localhost:3000/openapi.json

Use a snapshot or an OpenAPI validator in CI.

02

Test with app.fetch

TS
import { expect, test } from "bun:test";
import app from "./index";
test("rejects invalid task id", async () => { const response = await app.fetch(new Request("http://localhost/tasks/nope")); expect(response.status).toBe(400); });

Common mistakes

FAQ

FAQ

How is Scalar different from Swagger UI?

Both render OpenAPI documentation. Scalar is a modern API reference UI that can be mounted as a Hono route.

Does Hono require Node.js on Bun?

No. Hono uses Web APIs and runs on Bun, but always test runtime-specific dependencies in deployment.

Reviewed: 27 Aug 2026Applies to: Bun 1.3+Applies to: Hono 4.xApplies to: Zod 4.xApplies to: OpenAPI 3.1Applies to: ScalarTested with: Bun runtimeTested with: hono/zod-validatorTested with: @hono/zod-openapiTested with: @scalar/hono-api-reference

Conclusion

Describe the task — first 15 minutes of consultation are free.

Related Articles

AI Assistant Development Cost in 2026: RAG Chatbots, CRM Integrations, Guardrails, and Support
ai-assistants

AI Assistant Development Cost in 2026: RAG Chatbots, CRM Integrations, Guardrails, and Support

A practical buyer guide to AI assistant development cost in 2026: prototypes, RAG chatbots, knowledge-base assistants, CRM and website integrations, guardrails, evaluations, monitoring, and support.

AI for landing page development: where it speeds up launches and where it hurts conversion
blogs

AI for landing page development: where it speeds up launches and where it hurts conversion

A practical research piece on using AI for landing page development: v0, Webflow AI, Builder.io, Framer-like builders, UX generation, copy, SEO, personalization, A/B testing, template risk, accessibility, security and technical debt.

AI SEO / GEO in 2026: Your Next Customers Aren’t Humans — They’re Agents
growth

AI SEO / GEO in 2026: Your Next Customers Aren’t Humans — They’re Agents

Search is shifting from clicks to answers. Bots and AI agents crawl, cite, recommend, and increasingly buy. Learn what AI SEO / GEO means, why classic SEO is no longer enough, and how PAS7 Studio helps brands win visibility in the agentic web.

The most powerful Apple chip yet? M5 Pro and M5 Max are breaking records
blogs

The most powerful Apple chip yet? M5 Pro and M5 Max are breaking records

A data-backed March 2026 analysis of Apple M5 Pro and M5 Max. We break down why these chips can credibly be called Apple's most powerful pro laptop silicon, how they compare with M4 Pro, M4 Max, M1 Pro, M1 Max, and how they stack up against Intel and AMD laptop rivals.

Professional development for your business

We create modern web solutions and bots for businesses. Learn how we can help you achieve your goals.