Next.js
Use Silgi with Next.js App Router — API routes with full type safety and protocol support.
Silgi integrates with Next.js App Router via catch-all API routes. Full content negotiation (JSON, MessagePack, devalue) works out of the box.
Setup
Create a catch-all API route:
// app/api/[...path]/route.ts
import { } from 'silgi/nextjs'
import { } from '~/server/rpc'
const = (, {
: () => ({
: getDB(),
: .(.headers),
}),
})
export { as , as }Procedures are accessible at:
POST /api/users/list
POST /api/users/create
GET /api/healthServer Actions
For server-first React apps, use React Server Actions instead of API routes:
// app/actions.ts
'use server'
import { } from 'silgi/react'
export const = (appRouter.users.list)Edge Runtime
The handler uses standard Fetch API — works on both Node.js and Edge runtime:
export const = 'edge'Silgi compiles the router once at module load time. Next.js caches module imports across requests, so the compilation cost is paid only once per cold start.
Analytics and Scalar
Enable the built-in analytics dashboard or Scalar API reference directly in the adapter:
const = createHandler(appRouter, {
: () => ({ : .(.headers) }),
: {
: process.env.ANALYTICS_TOKEN,
},
: true,
})What's next?
- Analytics — built-in monitoring dashboard
- React Server Actions —
[error, data]tuple pattern - TanStack Query — React Query integration
- Integrations — other available integrations