본문으로 건너뛰기
버전: 10.x

Concepts

What is RPC? What mindset should I adopt?​

It's just functions​

RPC is short for "Remote Procedure Call". It is a way of calling functions on one computer (the server) from another computer (the client). With traditional HTTP/REST APIs, you call a URL and get a response. With RPC, you call a function and get a response.

ts
// HTTP/REST
const res = await fetch('/api/users/1');
const user = await res.json();
// RPC
const user = await api.users.getById({ id: 1 });
ts
// HTTP/REST
const res = await fetch('/api/users/1');
const user = await res.json();
// RPC
const user = await api.users.getById({ id: 1 });

tRPC (TypeScript Remote Procedure Call) is one implementation of RPC, designed for TypeScript monorepos. It has its own flavor, but is RPC at its heart.

Don't think about HTTP/REST implementation details​

If you inspect the network traffic of a tRPC app, you'll see that it's fairly standard HTTP requests and responses, but you don't need to think about the implementation details while writing your application code. You call functions, and tRPC takes care of everything else. You should ignore details like HTTP Verbs, since they carry meaning in REST APIs, but in RPC form part of your function names instead, for instance: getUser(id) instead of GET /users/:id.

Vocabulary​

Below are some terms that are used frequently in the tRPC ecosystem. We'll be using these throughout the documentation, so it's good to get familiar with them. Most of these concepts also have their own pages in the documentation.

용어설명
프로시저 ↗API 엔드포인트입니다. 쿼리, 뮤테이션, 구독중 하나일 수 있습니다.
쿼리데이터를 가져오는 프로시저입니다.
뮤테이션데이터를 생성하거나 수정하거나 삭제하는 프로시저입니다.
구독 ↗지속적인 연결을 만들고 변경 사항을 수신하는 프로시저입니다.
라우터 ↗하나의 네임스페이스 아래에 모인 프로시저 및 다른 라우터의 모음입니다.
컨텍스트 ↗모든 프로시저에서 접근할 수 있는 값입니다. 세션 상태나 데이터베이스 연결 등에 주로 사용합니다.
미들웨어 ↗프로시저 실행 전후에 코드를 실행할 수 있는 함수입니다. 컨텍스트를 수정할 수 있습니다.
검증 ↗"이 입력 데이터에 필요한 값이 올바르게 들어 있나요?"