tRPC for Builders
tRPC lets you call server functions from the client with full TypeScript type safety — no REST endpoints, no OpenAPI schema, no code generation. This course teaches you to set up tRPC in Next.js App Router, write type-safe queries and mutations, validate inputs with Zod, add authentication middleware, and test your router.
What you'll learn
Course outline
Free — start now
Full course — $49 one-time
Input Validation with Zod
Schema validation that propagates types to the client
Middleware — Auth and Rate Limiting
Protect procedures and enforce access control
Subscriptions and Real-Time Data
Push updates from server to client with tRPC subscriptions
Infinite Queries and Pagination
Cursor-based pagination with useInfiniteQuery
Error Handling and Custom Codes
TRPCError, error formatters, and client-side handling
Testing tRPC Routers
Unit and integration tests for your API layer
Get the full course
All 9 lessons. End-to-end type-safe APIs with no schema to maintain and no code generation.
Written by the RadarTrek editorial team · Reviewed June 2026
About this course
tRPC is a TypeScript library that lets you call server functions from the client as if they were local functions — with full end-to-end type safety, zero code generation, and no schema to maintain. In a traditional REST API, you define a route on the server (POST /api/users), write a request body type, implement the handler, and then write a separate fetch call on the client that must manually match the server's expected shape. Any mismatch between server and client types is a runtime error. tRPC eliminates this category of bug entirely: your server functions and their return types are directly inferred on the client, so TypeScript catches mismatches at compile time rather than in production.
In the Next.js App Router ecosystem, tRPC integrates via a Route Handler on the server and a React Query-based client on the browser. The same router is used for server-side calls (in Server Components or Server Actions) without any HTTP overhead. tRPC is particularly popular in full-stack TypeScript teams building internal tools, SaaS products, and any application where the frontend and backend are developed by the same person or team. This course teaches the complete tRPC setup in Next.js 15 App Router: routers, procedures, Zod validation, middleware, subscriptions, and testing.
Frequently asked questions
What is tRPC and why would I use it instead of REST?
tRPC is a TypeScript RPC framework that makes API calls between your Next.js server and client fully type-safe with no code generation. In a REST API, you manually write the request/response types on both sides and hope they stay in sync. With tRPC, the server procedure's input and output types are automatically inferred by the client — TypeScript will catch any mismatch before your code runs. The tradeoff is that tRPC is TypeScript-only and couples your frontend to your backend, making it unsuitable for public APIs consumed by third parties.
Does tRPC work with Next.js App Router?
Yes — tRPC 11+ has first-class App Router support. You create a route handler at app/api/trpc/[trpc]/route.ts that handles all tRPC requests. On the client, tRPC integrates with React Query (TanStack Query) for automatic caching, loading states, and mutation handling. Server Components can call tRPC procedures directly without an HTTP request using the server-side caller. This course covers the App Router setup pattern specifically.
Is tRPC the same as GraphQL?
No — tRPC and GraphQL solve a similar problem (type-safe API contracts) but with completely different architectures. GraphQL defines a schema in a separate language (SDL), requires code generation tools to produce TypeScript types, and is designed for complex querying with multiple consumers. tRPC uses TypeScript as the schema language directly, requires zero code generation, and is designed for tight frontend-backend coupling where both sides are in TypeScript. For public APIs or complex querying needs, GraphQL is still valuable. For internal full-stack TypeScript apps, tRPC is usually simpler.
What is Zod and why does tRPC use it?
Zod is a TypeScript schema validation library that lets you define the shape of data (e.g., a user creation object) with a fluent API and get TypeScript types inferred automatically from the schema. tRPC uses Zod to validate the input of procedures — you define a Zod schema for what your procedure accepts, tRPC validates it at runtime and infers the TypeScript type so your handler is typed correctly. Zod is now the standard input validation library in the Next.js and tRPC ecosystem.
How does tRPC handle authentication?
tRPC uses middleware to enforce authentication. A typical pattern is to create an authedProcedure that wraps the base procedure with middleware that reads the session from the request context, throws an UNAUTHORIZED TRPCError if there is no session, and passes the verified user object to the next handler. This means protected procedures automatically have a typed, non-null user in their context — no manual null checks required. The same middleware pattern handles rate limiting, permission checks, and any other cross-cutting concerns.