Hono + Zod validator API: working versions (tested 2026-10-15)
Hono routes with @hono/zod-validator for JSON and query validation, tested with app.request().
passed3 passed · 0 failed2026-10-15 13:08 UTC- Status
- passed
- Last passed
- 2026-10-15 13:08 UTC
- Tests
- 3 / 3
- Language
- TypeScript
- Runtime
- node v22.23.3
npm install --no-audit --no-fund --ignore-scripts=false npm test
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38738874208
The code
Exactly the files that passed. Your agent can pull them with get_recipe("hono-zod-validator") (install), or see them on GitHub.
{
"name": "hono-zod-validator",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"hono": "4.13.13",
"zod": "4.6.7",
"@hono/zod-validator": "0.9.1"
},
"devDependencies": {
"tsx": "4.23.15",
"@types/node": "24.19.2"
}
}
import { Hono } from "hono";
import { zValidator } from "@hono/zod-validator";
import { z } from "zod";
const Post = z.object({ title: z.string().min(3), body: z.string() });
const Page = z.object({ page: z.coerce.number().int().min(1).default(1) });
export const app = new Hono()
.post("/posts", zValidator("json", Post), (c) => c.json({ ok: true, post: c.req.valid("json") }, 201))
.get("/posts", zValidator("query", Page), (c) => c.json({ page: c.req.valid("query").page }));
import { test } from "node:test";
import assert from "node:assert/strict";
import { app } from "../src/app.ts";
test("valid json passes", async () => {
const res = await app.request("/posts", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ title: "Hello", body: "x" }) });
assert.equal(res.status, 201);
});
test("invalid json is 400", async () => {
const res = await app.request("/posts", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ title: "Hi" }) });
assert.equal(res.status, 400);
});
test("query is coerced", async () => {
const res = await app.request("/posts?page=3");
assert.deepEqual(await res.json(), { page: 3 });
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.
Related stacks
Hono + @hono/zod-openapi typed routes with generated OpenAPI docs
Define Hono routes with createRoute and Zod schemas so requests are validated, handlers are typed and an OpenAPI 3.1 document is generated at /doc.
Hono + Drizzle ORM + SQLite REST API (Vitest)
CRUD REST API in Hono backed by Drizzle ORM on better-sqlite3, with Zod validation, tested with Vitest and app.request().
Hono + hono/jwt bearer auth with Zod login
Issue HS256 JWTs from a Zod-validated login route in Hono and guard routes with the built-in jwt middleware.
Anthropic TypeScript SDK tool use loop, tested with a mocked fetch
Run a Claude tool_use loop with the official Anthropic SDK and Zod-validated tool inputs, tested offline with an injected fetch.