
tRPC Has Zero Boilerplate — Type-Safe APIs Without Code Generation
End-to-End Type Safety Without GraphQL tRPC gives you type-safe API calls between your frontend and backend. No schema files, no code generation, no runtime overhead. Server import { initTRPC } from " @trpc/server " ; import { z } from " zod " ; const t = initTRPC . create (); const appRouter = t . router ({ getUser : t . procedure . input ( z . object ({ id : z . string () })) . query ( async ({ input }) => { return { id : input . id , name : " John " , email : " john@example.com " }; }), createUser : t . procedure . input ( z . object ({ name : z . string (), email : z . string (). email () })) . mutation ( async ({ input }) => { return { id : " new-id " , ... input }; }), }); export type AppRouter = typeof appRouter ; Client import { createTRPCClient } from " @trpc/client " ; import type { AppRouter } from " ./server " ; const client = createTRPCClient < AppRouter > ({ url : " http://localhost:3000 " }); // Fully typed! IDE autocomplete works. const user = await client . getUser . q
Continue reading on Dev.to Tutorial
Opens in a new tab




