Hono Plugin
Use the hono plugin when your app already uses Hono or when you want Typeweaver to fit directly into a Hono router setup.
It generates one Hono router per resource, such as TodoHono.
Install note
For this path, install the plugin package and Hono itself:
npm install -D @rexeus/typeweaver-hono
npm install hono
Generate Hono output
npx typeweaver generate --input ./api/spec/index.ts --output ./api/generated --plugins clients,hono
Implement handlers and mount the generated router
Assuming your todo resource currently contains a single GetTodo operation:
import { Hono } from "hono";
import {
TodoHono,
createGetTodoSuccessResponse,
createTodoNotFoundErrorResponse,
} from "./api/generated";
const todoRouter = new TodoHono({
requestHandlers: {
async handleGetTodoRequest(request) {
if (request.param.todoId !== "todo_123") {
return createTodoNotFoundErrorResponse({
body: {
message: "Todo not found",
todoId: request.param.todoId,
},
});
}
return createGetTodoSuccessResponse({
body: {
id: "todo_123",
title: "Ship docs",
completed: false,
},
});
},
},
});
const app = new Hono();
app.route("/api", todoRouter);
The generated class wires the Hono route definitions for the operations in that resource. Your job is to provide the handlers.
What the plugin does for you
At a high level, the generated Hono path:
- reads the incoming Hono request
- validates it against the operation contract
- calls your typed handler
- validates the response your handler returns
- sends the HTTP response back through Hono
That gives you contract enforcement without hand-writing request parsing and response checks for every route.
When to choose Hono
Choose this path when:
- your server already uses Hono
- you want to use Hono middleware and routing conventions
- you want generated resource routers that mount naturally into an existing Hono app
If you want a dependency-free, Fetch API-native path instead, see Server Plugin.