Hono
Void handlers run on Hono. Void depends on Hono internally, but if your app imports from hono/* directly, add hono to your app's dependencies first.
npm install honoOnce hono is installed in your app, you can use built-in middleware, helpers, and third-party Hono packages directly.
Built-in Middleware
Use Hono's built-in middleware in your global middleware files or per-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, but not cookies. Use it only on routes whose response is the same for everyone, never 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
Hono's context helpers are available on c in every handler:
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 the package in your app, then use it directly:
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:
import { HTTPException } from 'hono/http-exception';
// Throw typed HTTP errors
throw new HTTPException(404, { message: 'User not found' });For the full list of built-in middleware, see the Hono documentation.