ENATIV Logo
ENATIV
Back
© 2026 ENATIV
ProjectsServicesKnowledge hubContact
contact@enativ.pl
  1. Knowledge hub
  2. ›
  3. Backend & APIs
  4. ›
  5. tRPC

tRPC

A TypeScript API library where server types reach the client with no schema and no code generation.

Backend & APIsUsing since 2022 · Featured project: Gaia Lens (in the Code & Pepper team)

Category
Backend & APIs
Using since
2022
Featured project
Gaia Lensin the Code & Pepper team

In practice

I pick tRPC when the frontend and the backend share one TypeScript project and I do not want a separate API schema to maintain. It is in the stack of Gaia Lens and TPH Global, both in the Code & Pepper team. When clients use other languages, I pick GraphQL or REST.

What is tRPC?

tRPC is a library for building and consuming fully typesafe APIs with no schemas and no code generation. It rests on TypeScript type inference: the server exports the router type, and the client gets the input and output types of every procedure from it. A contract error shows up at build time, not in the browser of a visitor.

The server functions are procedures, queries and mutations, grouped into routers. To the client they look like a function call, and underneath they are plain HTTP requests. Adapters run them, among others for Next.js and Fastify.

Contract
Router type, no schema
Code generation
None
Procedures
Queries and mutations
Language
TypeScript on both sides

How I work with tRPC

I start by asking who will read this API. If only my own apps in one repository, tRPC makes the work simpler, because the contract is code, not a separate file to keep in step.

  1. Router and procedures

    I group procedures into routers and export the type of the main router for the client. The client then knows every procedure with its input and output, with no schema file and no generation step.

  2. Validation at the input

    I check a procedure input with a validator, such as Zod, because TypeScript types vanish at runtime and will not stop a bad request. The validator also gives the client the input type.

  3. Adapter and caching

    I pick the adapter to match the framework, for example Next.js. With HTTP caching I watch request batching, because personal data can end up in one batch.

tRPC or GraphQL?

Both make sure the client knows what the server returns. tRPC does it with TypeScript types, GraphQL with a schema that does not depend on a language.

tRPC and GraphQL compared
CriteriontRPCGraphQL
Where the contract livesRouter type on the server, no schemaA GraphQL schema, described separately
Languages on both sidesTypeScript on both server and clientMany languages, one shared schema
Client typesInferred from the server, no code generationTools read the schema through introspection
Entry pointProcedures: queries and mutationsUsually one address for the whole API
Response shapeThe procedure on the server sets itThe client picks fields in the query
HTTP cachingQueries are plain GET requests, headers workThe address names no object, ids are needed

It usually comes down to team preference

The choice between tRPC and GraphQL usually comes down to what the team prefers to maintain, not to one right answer.

In newer Next.js

tRPC is really nice to work with, but in Next.js with cache components it may no longer be needed.

tRPC is in the stack of Gaia Lens and TPH Global, both in the Code & Pepper team, and GraphQL in Kuma.de and Little Birdie.

Frequently asked questions

No. The types come from TypeScript: the server exports the router type and the client imports it, so changing a procedure shows an error in the client editor straight away. The price is assuming both ends are in TypeScript and share one type, which is easiest in a single repository.
It does not have to. tRPC procedures are plain HTTP requests, so it can sit as an endpoint next to an existing REST API and you do not need to rewrite it at once. You add new procedures step by step, and the old endpoints keep working for as long as someone uses them.
Through adapters, among others for Next.js, Express, Fastify, AWS Lambda and a plain Node.js HTTP server. You check the input with a validator, such as Zod. I match the adapter to the project.
Yes, because queries are plain GET requests and the standard HTTP cache headers work. Request batching, though, can mix personal data with public data, so I set headers carefully or leave them out for logged-in requests.

On this page

  • In practice
  • What is tRPC?
  • How I work with tRPC
  • tRPC or GraphQL?
  • Frequently asked questions

Related topics

  • tRPC
  • TypeScript
  • Next.js
  • GraphQL
  • React
  • Node.js

Related services

  • Web ApplicationsModern, fast and scalable web applications using React and Next.js.

Everything in one TypeScript project?

Tell me who will use the API and in which languages. We will decide together whether tRPC is enough or whether you need GraphQL or REST.

Describe your projectSee Gaia Lens