REST API (Express/Fastify) → tRPC
mediumtRPC gives end-to-end type safety between client and server with zero codegen. Best for full-stack TypeScript monorepos using Next.js or similar.
npm install @trpc/server @trpc/client @trpc/react-query @tanstack/react-query
Convert REST endpoints to tRPC procedures. GET → query, POST/PUT/DELETE → mutation.
import { initTRPC } from '@trpc/server'
const t = initTRPC.create()
export const appRouter = t.router({ hello: t.procedure.query(() => 'world') })Mount tRPC handler in your Next.js app/api/trpc/[trpc]/route.ts.
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
export const GET = (req) => fetchRequestHandler({ req, router: appRouter, endpoint: '/api/trpc' })Create trpc.ts with typed hooks. Replace fetch calls with useMutation/useQuery hooks.
import { createTRPCReact } from '@trpc/react-query'
export const trpc = createTRPCReact<AppRouter>()Input schemas replace express-validator or manual parsing. Types are inferred automatically.
t.procedure.input(z.object({ name: z.string() })).query(({ input }) => input.name)npm uninstall express
What this migration involves
Moving from REST API (Express/Fastify) to tRPC is rated medium and takes about 4-12h on a typical project. The guide breaks it into 6 steps, 6 of which ship with runnable commands and 1 with a verification check.
Related migrations
FAQ
How long does migrating from REST API (Express/Fastify) to tRPC take?
Around 4-12h for a typical project — 6 steps, difficulty rated medium, 6 of them with copy-paste commands.
Is moving from REST API (Express/Fastify) to tRPC reversible?
No reverse guide is tracked yet, so treat this as a one-way move and keep a full export of your REST API (Express/Fastify) data before you start.
What does tRPC cost compared to REST API (Express/Fastify)?
tRPC: open-source from $0/mo, free plan available.