tRPC Changes API Design for TypeScript Teams

The tRPC framework is altering how developers approach API design by offering end-to-end type safety between frontend and backend without requiring code generation. By inferring types directly, it eliminates the need for separate schema definitions used in REST or GraphQL. This approach is intended to reduce boilerplate code and allow developers to catch type-related bugs across the full stack during development.

- The project was created by Alex "KATT" Johansson and evolved from a 2020 proof-of-concept called ZodRPC by Colin McDonnell, the creator of the Zod validation library. - Unlike GraphQL, which is a query language allowing clients to request specific data fields, tRPC is a library where the server defines procedures that return a set data shape, simplifying the toolchain for full-stack TypeScript applications. - The major v10 release in November 2022 significantly improved the developer experience by enabling IDE features like "Go to Definition" to jump directly from a frontend call to the backend implementation. It also addressed performance bottlenecks in the TypeScript type checker that arose in large v9 applications. - By default, tRPC uses JSON for data serialization over standard HTTP, in contrast to the more performant binary Protocol Buffers and HTTP/2 transport used by gRPC. - tRPC is designed primarily for internal APIs where the client and server are part of the same monorepo or codebase, as it lacks a built-in mechanism for introspection or generating documentation for third-party consumers. - The framework offers built-in request batching, which automatically combines multiple requests made at the same time into a single HTTP call to reduce network overhead and improve performance. - It is framework-agnostic but provides adapters for most popular environments, including Next.js, Express, AWS Lambda, and the standard Fetch API.

Get your own daily briefing

Scout delivers personalized news, insights, and conversations tailored to your role and industry.

Download on the App Store

Shared from Scout - Be the smartest in the room.