ㅁㄴㅇㄹ

tRPC 문서 읽어보기

냠냠

tRPC(TypeScript Remote Procedure Call)

- An alternative to traditional REST or GraphQL

- since GraphQL is designed as a language-agnostic specification for implementing APIs, it doesn‘t take full advantage of the power of a lanauge like TypeScript. -> If your project is built with full-stack TS, you can share types directly between your client and server, without relying on code generation.

- Type errors with your API contracts will be caught at build time, reducing the surface for bugs in your application at runtime.

Vocabulary

- Procedure: API endpoint(can be 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 created a persistent connection and listens to changes.

- Router: a collection of procedures under a shared namespace.

- Context: stuff that every procedure can access. commonly used for thins 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?

Defining a backend router

서버쪽에서 만드는건 일단 스킵..

————

1. Setup the tRPC Client

client/index.ts

links in tRPC are similar to links in graphql, they let us control the data flow before being sent to the server.

In the example above, we use httpBatchLink, which automatically bathes up multiple calls into a single HTTP request.

For more in-depth usage of links, see the links documentation.

(You can compose links together into an array -> represents a link chain. This means that the tRPC client will execute the links inthe order they are added to the links array when doing a request and will execute them again in reverse when it‘s handling a reponse.)

2. Querying & mutating

client/index.ts

재미나다

카테고리
#기타

댓글 0



추천 포스트