@routegraph/hono
v1.0.0
Published
Hono v4 adapter for RouteGraph — runs on Node, Bun, Deno, and Cloudflare Workers.
Readme
@routegraph/hono
Hono adapter for RouteGraph — turns a loaded RouteGraph into a Hono app.
Runtime coverage
| Runtime | Supported |
|---|---|
| Node.js (via @hono/node-server) | ✓ |
| Bun | ✓ (Hono's native support) |
| Deno | ✓ (Hono's native support) |
| Cloudflare Workers | ✓ (Hono's native support) |
This adapter contains no runtime-specific code — it only builds on Hono's own Context API, so it inherits whatever runtimes Hono itself supports. It is exercised in this monorepo's tests and examples on Node.js via @hono/node-server.
Installation
pnpm add @routegraph/hono @routegraph/core hono zodhono is a peer dependency (>=4.0.0). On Node.js, you'll also need @hono/node-server to actually listen on a port.
createHonoRouter(graph)
function createHonoRouter(graph: RouteGraph): HonoUsage (Node.js)
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
import { RouteGraph } from '@routegraph/core'
import { createHonoRouter } from '@routegraph/hono'
const graph = new RouteGraph({ routesDir: './routes' })
await graph.load()
const app = new Hono()
app.route('/api', createHonoRouter(graph))
serve({ fetch: app.fetch, port: 3000 })For Bun, Deno, or Cloudflare Workers, mount createHonoRouter(graph) the same way (app.route('/api', ...)) and export/serve app.fetch using that runtime's own entry point — there is nothing Node-specific in the adapter itself.
Hono-specific notes
- Body parsing: the adapter calls
await c.req.json()itself forPOST/PUT/PATCHrequests — you don't need a separate body-parsing middleware. A missing or invalid JSON body is treated asundefined, letting your route's Zodbodyschema (if any) report the real validation failure instead of a generic parse error. - Query arrays: built from
c.req.queries()— a key that appears once resolves to astring, a key that appears more than once resolves tostring[]. This matches what@routegraph/clientproduces when serializing an array-valued query field. - Error handling: unlike Express, thrown handler errors are caught by the adapter itself and turned into a
500 { error: 'Internal server error' }JSON response — there's no equivalent of forwarding tonext(err). Use Hono's ownapp.onError(...)at the app level if you want centralized logging of those. - Docs UI:
routegraph dev's automatic docs-UI mounting is not implemented for Hono yet — seeexamples/with-express/index.hono.tsfor the manual bridging pattern (wrappingcreateDocsMiddleware's Connect-style signature into a Hono middleware).
Validation error format
Identical across every adapter:
{ "error": "Validation failed", "issues": [{ "field": "body.email", "message": "Invalid email", "code": "invalid_string" }] }Accessing the raw Hono Context
const handler: RouteHandler<typeof config> = async (req, res) => {
const c = req.raw as import('hono').Context
console.log(c.req.header('x-request-id'))
}