if (err) { console.error(err.message); } else { // data.name, data.id, data.role — inferred directly from the route! console.log(data.name, data.role); }
// 2. Exhaustive Error Narrowing // TypeScript narrows err.code to exactly the codes this route can return. // assertNever() is a compile-time guard — remove any case and TS errors. const [ data2
// 5b. IDE IntelliSense: Allowed Methods // Place cursor inside method — your IDE narrows to only what this route exports. awaitapiFetch("/api/users/34", { method: ""
DELETE
↵DELETE
GET
PUT
});
// 6. Static vs Dynamic Route Precedence // /api/users/active matches the static route exactly — not the [userId] segment. const [ activeUsers
next-zero-rpc is not a black-box framework—it's a paradigm. When you run init, we drop four files into your project. From that moment on, they are yours to modify, extend, or delete. Zero vendor lock-in.
Architectural Freedom
Because we don't take over your Next.js server, you are free to mix and match architectures. Need Server-Sent Events (SSE), WebSockets, or GraphQL alongside it? Go ahead. Study our generated files to verify this—there is no hidden framework magic.
Zero Boilerplate
You write standard Next.js API route handlers. No decorators, no schema registrations, no complex abstractions. The codegen reads what already exists and builds the type bridge automatically.
Validation Is Yours
Input validation stays inside your route handler where it belongs. This library doesn't impose a validation layer—that's a deliberate design choice to keep things non-invasive.
Installation
Deploy the type-safe bridge into your architecture.
01
Scaffold Core Files
Use the CLI to scaffold everything, or copy the files manually.
$ npx next-zero-rpc init
Creates lib/next-zero-rpc/ and generates the initial apiRegistry.ts automatically. Skip to Step 02.
02
Setup Next.js Watcher
Inject the plugin so the registry auto-updates on every route change during dev. Optional — applies to both CLI and manual installs.