0Pricing
tRPC End-to-End Type Safe APIs · 강의

첫 tRPC 프로젝트 설정하기

tRPC를 설치하고 라우터를 만든 뒤 클라이언트를 연결해 첫 번째 타입 안전 호출을 수행하는 과정을 따라갑니다.

첫 tRPC 프로젝트 설정하기은(는) CoddyKit의 무료 tRPC End-to-End Type Safe APIs 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 tRPC End-to-End Type Safe APIs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. tRPC End-to-End Type Safe APIs 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What We Are Building

You know what tRPC is and why type safety matters. Now you'll set up a real project and make your first end-to-end type-safe call.

Installing the Packages

tRPC ships as separate server and client packages. Install them alongside Zod for validation.

npm install @trpc/server @trpc/client zod

Initializing tRPC

Create one t object with initTRPC.create() — everything else (router, procedures) is built from it.

import { initTRPC } from "@trpc/server";

const t = initTRPC.create();

export const router = t.router;
export const publicProcedure = t.procedure;

Creating a Router

A router groups procedures. Here's a minimal one exposing a single greeting query.

export const appRouter = router({
  hello: publicProcedure.query(() => {
    return "Hello tRPC";
  }),
});

Exporting the Router Type

The core trick: export only the router's type, not its code. The client learns the full API shape with zero codegen.

export type AppRouter = typeof appRouter;

Serving the Router

Attach your router to an HTTP server using a tRPC adapter — here, the standalone createHTTPServer.

import { createHTTPServer } from "@trpc/server/adapters/standalone";

createHTTPServer({ router: appRouter }).listen(3000);

Creating the Client

The client imports the AppRouter type to unlock full autocomplete and type checking against your server.

import { createTRPCClient, httpBatchLink } from "@trpc/client";
import type { AppRouter } from "./server";

const client = createTRPCClient<AppRouter>({
  links: [httpBatchLink({ url: "http://localhost:3000" })],
});

Making the First Call

Call the procedure as if it were a local typed function — that's the whole point of tRPC.

const greeting = await client.hello.query();
console.log(greeting); // "Hello tRPC"

Type Safety in Action

Type safety in action: rename hello on the server and the client call becomes a compile error instantly — no runtime surprise.

Project Structure

A common project layout: server/trpc.ts for the t object, server/router.ts for procedures, and client/index.ts for the typed client.

Adding Inputs

Most procedures take input. Validate it with Zod and that input type flows to the client automatically.

greet: publicProcedure
  .input(z.object({ name: z.string() }))
  .query(({ input }) => "Hi " + input.name),

Quick Check

Test your setup knowledge.

Recap

Recap: you installed the tRPC packages, built a router and exported its type, and made a typed client call — a full end-to-end type-safe pipeline.

자주 묻는 질문

“첫 tRPC 프로젝트 설정하기” 강의는 무료인가요?

네 — “첫 tRPC 프로젝트 설정하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 tRPC End-to-End Type Safe APIs 강의 전체를 잠금 해제할 수 있습니다. tRPC End-to-End Type Safe APIs 강의에는 총 4개의 강의가 포함되어 있습니다.

“첫 tRPC 프로젝트 설정하기”에서 뭘 배우나요?

tRPC를 설치하고 라우터를 만든 뒤 클라이언트를 연결해 첫 번째 타입 안전 호출을 수행하는 과정을 따라갑니다. 브라우저에서 직접 실행하는 실습 코드로 tRPC End-to-End Type Safe APIs을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

tRPC End-to-End Type Safe APIs을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 tRPC End-to-End Type Safe APIs은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“첫 tRPC 프로젝트 설정하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 tRPC End-to-End Type Safe APIs 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 tRPC End-to-End Type Safe APIs 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. tRPC란 무엇인가요?
  2. 타입 안전성의 힘
  3. tRPC 핵심 개념 개요
  4. 첫 tRPC 프로젝트 설정하기
← tRPC End-to-End Type Safe APIs(으)로 돌아가기