Hono
SDK route handlers run on Hono. Hono's middleware and helpers work inside them. The SDK uses Hono internally. If your app imports from hono/* directly, add hono to your own dependencies first.
On this pageUse Hono's built-in middleware in your routes · Return responses with Hono's helpers · Add third-party Hono middleware and utilities
Install Hono
Now you will add hono to your app's dependencies.
npm install honoExample output: npm finishes with added N packages and no errors.
You can now use Hono's built-in middleware, its helpers and third-party Hono packages.
Built-in middleware
Use Hono's built-in middleware in a global middleware file or on a single route:
import { cors } from 'hono/cors';
// middleware/01.cors.ts
import { defineMiddleware } from 'void';
export default defineMiddleware(cors({ origin: 'https://example.com' }));import { cache } from 'hono/cache';
// routes/api/products.ts (per-route cache)
import { defineHandler } from 'void';
import { listProducts } from '../../lib/products';
export const GET = defineHandler(
cache({ cacheName: 'products', cacheControl: 'max-age=3600' }),
async () => ({ products: await listProducts() }),
);WARNING
cache() stores one response per URL and returns it to every visitor. It skips requests with an Authorization header. It does not skip requests with cookies. Use it only on routes that return the same response to everyone. Never use it on a route that reads the signed-in user. To cache pages, use revalidation, which skips requests that carry a cookie.
import { bearerAuth } from 'hono/bearer-auth';
// routes/api/webhooks/stripe.ts (per-route usage)
import { defineHandler } from 'void';
export const POST = defineHandler(bearerAuth({ token: 'webhook-secret' }), async (c) => {
const body = await c.req.json();
return { received: true };
});Response helpers
Every handler gets Hono's context helpers on c:
import { stream } from 'hono/streaming';
// routes/api/download.ts
import { defineHandler } from 'void';
export const GET = defineHandler((c) => {
return stream(c, async (stream) => {
await stream.write('chunk 1');
await stream.write('chunk 2');
});
});// routes/api/data.ts
import { defineHandler } from 'void';
export const GET = defineHandler((c) => {
c.header('X-Custom', 'value');
c.status(201);
return c.json({ created: true });
});Third-party middleware
Any hono/* or @hono/* package works. Install it in your app, then import it:
import { rateLimiter } from 'hono-rate-limiter';
// middleware/01.rate-limit.ts
import { defineMiddleware } from 'void';
export default defineMiddleware(rateLimiter({ windowMs: 60_000, limit: 100 }));Utilities
Hono's standalone helpers work anywhere in your code:
import { HTTPException } from 'hono/http-exception';
// Throw typed HTTP errors
throw new HTTPException(404, { message: 'User not found' });For all built-in middleware, see the Hono documentation.