Skip to content
BENIBIX Learn

tRPC

Development🔌 APIsAPI Architecture Styles

Also known as TypeScript Remote Procedure Call, tRPC API, tRPC Router

A TypeScript tool. The front end calls server code, and both share the same types.

Think of it like

Think of it like a phone where both people speak the same language. Nothing gets lost in translation.

Example

Emma renames a field on her server. Her editor at once marks every front-end line that used the old name.

Why it matters

Mistakes between front end and back end show up while you type, not after you ship.

Definition

tRPC is a TypeScript tool for building APIs where the front end and back end share types. You write a function on the server. The front end calls it as if it were a local function. If the server changes, the front end shows a type error at once. It needs no schema file and no generated code, but both sides must use TypeScript.

Example code

typescript
const order = await trpc.order.byId.query({ id: 42 });
console.log(order.total);
The front end calls the server function, and its types come along.
Like any client, tRPC calls an endpoint, but with shared types.

Common mistake

Using it for a public API. Outside users may not use TypeScript, so REST or GraphQL fits better.

Key takeaways

  1. 1
    Shared types. Both sides see the same shapes.
  2. 2
    No schema file. The code is the contract.
  3. 3
    TypeScript only. Best when one team owns both ends.

Compare