
tRPC Has a Free API — End-to-End TypeScript APIs Without Code Generation
tRPC lets you build fully type-safe APIs without schemas, code generation, or REST conventions. Define a function on the server — call it from the client with full autocompletion. Why tRPC? Zero code generation — types flow automatically from server to client Full autocompletion — IntelliSense for every API call No REST — no routes, no HTTP methods, no serialization headaches Works with — Next.js, Nuxt, SvelteKit, Express, Fastify Quick Start npm install @trpc/server @trpc/client @trpc/react-query Server // server/trpc.ts import { initTRPC , TRPCError } from ' @trpc/server ' ; import { z } from ' zod ' ; const t = initTRPC . context < Context > (). create (); const isAuthed = t . middleware (({ ctx , next }) => { if ( ! ctx . user ) throw new TRPCError ({ code : ' UNAUTHORIZED ' }); return next ({ ctx : { user : ctx . user } }); }); export const publicProcedure = t . procedure ; export const protectedProcedure = t . procedure . use ( isAuthed ); export const router = t . router ; // se
Continue reading on Dev.to Tutorial
Opens in a new tab


