How to add Hono to an existing Next.js app

Mount and test a validated Hono endpoint inside one Next.js App Router application.

By Antoine RossPublished

Mount Hono in an App Router Route Handler, then call it at the same origin as your Next.js app. This gives you Hono routing and middleware without starting another server. The architecture comparison helps you decide when a separate service is worthwhile.

Add a validated endpoint

Start in an existing Next.js App Router project with Node.js. If app lives under src, use below. Install the dependencies:

npm install hono @hono/zod-validator zod

Create app/api/[[...route]]/route.ts. Check for an existing catch-all API route first: two handlers cannot own the same route. Hono's Next.js adapter passes the Next.js request to the app; its base path must match the mount.

app/api/[[...route]]/route.ts
import { Hono } from 'hono';
import { handle } from 'hono/vercel';
import { zValidator } from '@hono/zod-validator';
import { z } from 'zod';

const app = new Hono().basePath('/api');
const input = z.object({ name: z.string().trim().min(1).max(80) });

app.post('/greetings', zValidator('json', input), (c) => {
  const { name } = c.req.valid('json');
  return c.json({ greeting: `Hello, ${name}!` });
});

export const runtime = 'nodejs';
export const POST = handle(app);

Validation rejects invalid input before the handler runs. Add other HTTP exports only when you implement those methods. This example does not authenticate callers or store data; add authorization before exposing protected operations.

Try both paths

Run your usual Next.js development server and send requests to its actual local origin. For the default port:

curl -i http://localhost:3000/api/greetings -H 'Content-Type: application/json' -d '{"name":"Ada"}'
curl -i http://localhost:3000/api/greetings -H 'Content-Type: application/json' -d '{"name":""}'

The first returns HTTP 200 with {"greeting":"Hello, Ada!"}; the second returns HTTP 400. A 404 usually means the mount directory, basePath, or URL do not agree. A JSON validator also needs the Content-Type header. Keep existing specific API routes and check their routing precedence before replacing a catch-all.

CoreMVP's premium Next.js template already connects same-origin Hono routes to services and repositories, so you can extend an existing validated API instead of assembling that boundary yourself. See the backend guide.