
tRPC Has a Free RPC Framework: Full-Stack Type Safety Without Code Generation or Schema Files
GraphQL needs schemas, resolvers, codegen, and a client library. REST needs OpenAPI specs, validation middleware, and typed fetch wrappers. Both require you to define your API contract twice — once on the server, once on the client. What if your client automatically knew every API endpoint's input and output types — with zero code generation? That's tRPC. Define a function on the server. Call it from the client. TypeScript handles the rest. How It Works // server/router.ts 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 . user . findUnique ({ where : { id : input . id } }); return user ; // { id: string, name: string, email: string } }), createUser : t . procedure . input ( z . object ({ name : z . string (). min ( 1 ), email : z . string (). email (), })) . mutation (
Continue reading on Dev.to React
Opens in a new tab




