What if your API client knew every endpoint, parameter, and return type — without generating any code?
tRPC gives you end-to-end type safety between your server and client. Define procedures on the server, call them from the client — TypeScript infers everything.
Why tRPC
- Zero code generation — types flow from server to client via inference
- Full autocomplete — your IDE knows every endpoint and its types
- Validation included — Zod, Yup, or any validator
- React Query integration — built-in hooks with caching
- Subscriptions — WebSocket support
- Framework-agnostic — works with Next.js, Express, Fastify, Deno
Quick Start
npm install @trpc/server @trpc/client @trpc/react-query
Server:
import { initTRPC } from "@trpc/server";
import { z } from "zod";
const t = initTRPC.create();
export const appRouter = t.router({
getUser: t.procedure
.input(z.object({ id: z.string() }))
.query(async ({ input }) => {
const user = await db.users.findById(input.id);
return user; // TypeScript knows the shape
}),
createPost: t.procedure
.input(z.object({ title: z.string(), content: z.string() }))
.mutation(async ({ input }) => {
return db.posts.create(input);
}),
});
export type AppRouter = typeof appRouter;
Client:
import { trpc } from "@/utils/trpc";
function UserProfile({ id }: { id: string }) {
// Fully typed — autocomplete on query name and input
const { data: user } = trpc.getUser.useQuery({ id });
// user is fully typed — TypeScript knows the shape from the server
return <h1>{user?.name}</h1>;
}
Real Use Case
A team used REST endpoints with hand-written TypeScript types for request/response. After every backend change, someone forgot to update the frontend types — runtime crashes in production. After migrating to tRPC, type mismatches became compile errors. Zero type-related production bugs in 6 months.
When to Use tRPC
- Full-stack TypeScript apps (monorepo or same codebase)
- Internal APIs where you control both server and client
- Teams that want zero-overhead type safety
- Projects tired of maintaining OpenAPI specs
Get Started
Visit trpc.io — open source, MIT licensed, 34K+ GitHub stars.
Need custom data pipelines or scraping solutions? Check out my Apify actors or email me at spinov001@gmail.com for custom solutions.
Top comments (0)