
tRPC v11 Has a Free API That Eliminates the API Layer Between Frontend and Backend
tRPC v11 lets you call backend functions from the frontend with zero API layer — full type safety, no codegen, no schemas. Define Your API: Procedures import { initTRPC , TRPCError } from " @trpc/server " ; import { z } from " zod " ; const t = initTRPC . context < Context > (). create (); const appRouter = t . router ({ products : t . router ({ list : t . procedure . input ( z . object ({ category : z . string (). optional (), minPrice : z . number (). optional (), maxPrice : z . number (). optional (), page : z . number (). default ( 1 ), })) . query ( async ({ input }) => { return db . product . findMany ({ where : { category : input . category , price : { gte : input . minPrice , lte : input . maxPrice }, }, skip : ( input . page - 1 ) * 20 , take : 20 , }); }), create : t . procedure . input ( z . object ({ title : z . string (). min ( 1 ), price : z . number (). positive (), url : z . string (). url (), })) . mutation ( async ({ input }) => { return db . product . create ({ data
Continue reading on Dev.to React
Opens in a new tab



