Experience the full power of TypeScript inference to boost productivity
for your full-stack application.
Many thanks to all of our amazing sponsors!
Automatic typesafety
Made a server side change? TypeScript will warn you of errors on your client before you even save the file!
Snappy DX
tRPC has no build or compile steps, meaning no code generation, runtime bloat or build step.
Framework agnostic
Compatible with all JavaScript frameworks and runtimes. It’s easy to add to your existing projects.
Autocompletion
Using tRPC is like using an SDK for your API’s server code, giving you confidence in your endpoints.
Light bundle size
tRPC has zero dependencies and a tiny client-side footprint making it lightweight.
Batteries included
We provide adapters for React, Next.js, Express, Fastify, AWS Lambda, Solid, Svelte, and more.
Simple to use with
unmatched developer experience
It’s quick and easy to get started with tRPC to build a typesafe API.
ts
const
t =initTRPC .create ();const
router =t .router ;const
publicProcedure =t .procedure ;const
appRouter =; ... 5 more ...; _output_out: typeof unsetMarker; }, `Hello ${string}`>; }>(procedures: { ...; }) => CreateRouterInner<...>">router ({
; ... 5 more ...; _output_out: typeof unsetMarker; }, `Hello ${string}`>">greeting :publicProcedure .
>(schema: z.ZodObject<{ name: z.ZodString; }, "strip", z.ZodTypeAny, { name: string; }, { ...; }>): ProcedureBuilder<...>">input (z .export object">object ({name :z .string () })).
query ((opts ) => {const {
input } =opts ;const input: { name: string; }
return `Hello ${
input .name }` asconst ;}),
});
export type
AppRouter = typeofappRouter ;
ts
const
t =initTRPC .create ();const
router =t .router ;const
publicProcedure =t .procedure ;const
appRouter =; ... 5 more ...; _output_out: typeof unsetMarker; }, `Hello ${string}`>; }>(procedures: { ...; }) => CreateRouterInner<...>">router ({
; ... 5 more ...; _output_out: typeof unsetMarker; }, `Hello ${string}`>">greeting :publicProcedure .
>(schema: z.ZodObject<{ name: z.ZodString; }, "strip", z.ZodTypeAny, { name: string; }, { ...; }>): ProcedureBuilder<...>">input (z .export object">object ({name :z .string () })).
query ((opts ) => {const {
input } =opts ;const input: { name: string; }
return `Hello ${
input .name }` asconst ;}),
});
export type
AppRouter = typeofappRouter ;
The first step to creating a tRPC API is to define your procedures.
Procedures are the functions we will use to build your backend. They’re composable and can be queries, mutations, or subscriptions. Routers contain multiple procedures.
In this procedure, we use a
Zod validator to ensure the input from the client has exactly the shape that our procedure expects. We will also return a simple text string from the query.
At the end of the file, we export the type of the router so we can use it in our frontend code in just a few moments.
ts
const { listen } = createHTTPServer({
router: appRouter,
});
// The API will now be listening on port 3000!
listen(3000);
ts
const { listen } = createHTTPServer({
router: appRouter,
});
// The API will now be listening on port 3000!
listen(3000);
Next, we create our HTTP server using our appRouter
. We now have a tRPC server running!
tRPC has many adapters so it can meet you where you are. Next.js, Express, the Fetch API (Astro, Remix, SvelteKit, Cloudflare Workers, etc.), Fastify, AWS Lambda, or a vanilla Node HTTP server.
ts
const
; ... 5 more ...; _output_out: typeof unsetMarker; }, `Hello ${string}`>; }>">trpc ={ { >`Hello>{ >{ >
Read More


Sign Up to Our Newsletter
Be the first to know the latest updates
Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.