Course contentsShow
← TypeScript
Lesson 1552 of 1,79636. tRPC and End-to-End Type SafetyFree lesson

RPC vs REST: The Conceptual Shift

How tRPC treats API calls as remote procedure calls rather than resource-oriented REST endpoints.

RPC vs REST: The Conceptual Shift

What you'll learn: How tRPC treats API calls as remote procedure calls rather than resource-oriented REST endpoints.

The Fundamental Difference

When you use REST, you think in terms of resources and HTTP verbs. You're making requests to endpoints like GET /users/123 or POST /articles. The focus is on what resource you're accessing and what action you're performing on it.

When you use RPC (Remote Procedure Call), you think in terms of functions you're calling. You're not requesting a resource—you're invoking a function that happens to run on a different machine. With tRPC, getUser(123) and createArticle(data) are just function calls, even though they execute on the server.

The Mental Model Shift

REST Thinking:

  • "I need to GET the user resource at this URL"
  • "I'm POSTing to the articles collection"
  • HTTP methods matter, URLs are paths to resources

RPC Thinking:

  • "I'm calling the getUser function with ID 123"
  • "I'm calling the createArticle function with this data"
  • Function names matter, you're invoking remote logic

Why This Matters for TypeScript

With REST, your frontend and backend are decoupled by HTTP. Types don't automatically flow across that boundary—you need OpenAPI generators, manual type definitions, or runtime validation to bridge the gap.

With RPC (specifically tRPC), calling a server function looks and feels like calling a local function. The type signature of the server function becomes the type signature of the client call. There's no URL construction, no manual HTTP method selection, no type translation layer.

Key Takeaway: tRPC makes remote server functions look like local function calls, shifting from resource-oriented REST endpoints to direct procedure invocations with automatic type safety across the network boundary.