Skip to content

tRPC

Medium — good to knowBackend

ELI5 — The Vibe Check

tRPC lets you call your backend functions directly from the frontend with full TypeScript type safety — no REST endpoints, no API schema, no code generation. Define a function on the server, and TypeScript knows exactly what you can call and what it returns on the client. Change the backend? The frontend gets red squiggles instantly. It's like your backend and frontend share one brain.

Real Talk

tRPC is a TypeScript framework that enables end-to-end type-safe APIs without code generation or runtime schemas. The server defines procedures (queries, mutations, subscriptions) using TypeScript, and the client infers types directly from the server code through TypeScript's type system. It works with any framework (Next.js, Nuxt, Express) and eliminates the API contract layer (no OpenAPI, no GraphQL schema). Best suited for full-stack TypeScript monorepos.

Show Me The Code

// Server
const appRouter = router({
  getUser: publicProcedure
    .input(z.object({ id: z.string() }))
    .query(async ({ input }) => {
      return db.user.findUnique({ where: { id: input.id } });
    }),
});

// Client — fully typed, no codegen!
const user = await trpc.getUser.query({ id: '123' });
console.log(user.name); // TypeScript knows the shape!

When You'll Hear This

"Use tRPC — we're already full-stack TypeScript, so why maintain a REST API?" / "tRPC eliminates the 'did I update the API types?' problem."

Made with passive-aggressive love by manoga.digital. Powered by Claude.