Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.45 KB

File metadata and controls

53 lines (40 loc) · 1.45 KB

API: Hono + oRPC

depends_on: [00-runtime.md, 05-schema.md] tags: [api, http, rpc, workers] Last updated: 2026-07-10

Hono — Web Standards HTTP framework

Bun detects the fetch export automatically and calls Bun.serve():

import { Hono } from "hono";
const app = new Hono();
app.get("/", (c) => c.text("Hello"));
export default app;

Routers

Router Speed Use case
RegExpRouter Fastest Static route set
LinearRouter Second Per-request initialisation (ISR)
SmartRouter Auto Default, picks the best

oRPC — Contract-first RPC

Why oRPC over Hono RPC / tRPC

  • Type safety covers request, response, error, and middleware (Hono RPC covers only request and response)
  • Contract-first: define the contract before the implementation
  • Framework integration: TanStack Query native
  • vs tRPC: type checking 1.6x faster, runtime 2.8x faster, bundle 2x smaller
  • Multi-runtime: CF Workers, Deno, Bun, Node

Integration example

const getPost = os
  .use(dbProvider)
  .use(requireAuth)
  .route({ method: "GET", path: "/post/{id}" })
  .input(z.object({ id: z.string() }))
  .errors({ NOT_FOUND: { data: z.object({ id: z.string() }) } })
  .handler(async ({ input, context }) => {
    // context.user is typed
  });

Official docs