개념
비공식 베타 번역
이 페이지는 PageTurner AI로 번역되었습니다(베타). 프로젝트 공식 승인을 받지 않았습니다. 오류를 발견하셨나요? 문제 신고 →
RPC란 무엇인가? 어떤 마인드셋을 가져야 할까?
단순히 함수 호출일 뿐
RPC는 "Remote Procedure Call"의 약자입니다. 한 컴퓨터(서버)의 함수를 다른 컴퓨터(클라이언트)에서 호출하는 방식입니다. 기존 HTTP/REST API는 URL을 호출해 응답을 받지만, RPC는 함수를 호출해 응답을 받습니다.
ts// HTTP/RESTconst res = await fetch('/api/users/1');const user = await res.json();// RPCconst user = await api.users.getById({ id: 1 });
ts// HTTP/RESTconst res = await fetch('/api/users/1');const user = await res.json();// RPCconst user = await api.users.getById({ id: 1 });
tRPC(TypeScript Remote Procedure Call)는 TypeScript 모노레포를 위해 설계된 RPC 구현체입니다. 고유한 특색이 있지만 본질적으로 RPC입니다.
HTTP/REST 구현 세부사항은 신경 쓰지 마세요
tRPC 앱의 네트워크 트래픽을 살펴보면 표준 HTTP 요청/응답 형태지만, 애플리케이션 코드 작성 시 구현 세부사항을 고민할 필요는 없습니다. 함수를 호출하면 tRPC가 나머지를 처리합니다. HTTP 메서드 같은 세부사항은 무시해야 합니다. REST API에서는 이러한 요소가 의미를 지니지만, RPC에서는 함수 이름의 일부로 표현됩니다. 예를 들어 GET /users/:id 대신 getUser(id)처럼 사용합니다.
용어 사전
다음은 tRPC 생태계에서 자주 사용되는 용어들입니다. 문서 전반에 걸쳐 이 용어들을 사용하므로 미리 숙지하는 것이 좋습니다. 대부분의 개념은 문서 내 별도 페이지에서도 다루고 있습니다.
| Term | Description |
|---|---|
| Procedure ↗ | API endpoint - can be a query, mutation, or subscription. |
| Query | A procedure that gets some data. |
| Mutation | A procedure that creates, updates, or deletes some data. |
| Subscription ↗ | A procedure that creates a persistent connection and listens to changes. |
| Router ↗ | A collection of procedures (and/or other routers) under a shared namespace. |
| Context ↗ | Stuff that every procedure can access. Commonly used for things like session state and database connections. |
| Middleware ↗ | A function that can run code before and after a procedure. Can modify context. |
| Validation ↗ | "Does this input data contain the right stuff?" |