Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
5分でtRPCに入門する
Search
Haruki Murasaki
October 27, 2022
Programming
680
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
5分でtRPCに入門する
2022/10/27
https://rakus.connpass.com/event/258984/
Haruki Murasaki
October 27, 2022
More Decks by Haruki Murasaki
See All by Haruki Murasaki
開発速度を5倍早くするVSCodeの拡張機能を作った
purp1eeeee
2
490
Other Decks in Programming
See All in Programming
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
100
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
620
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
140
mrbgem 三角測量 開発
ogom
0
200
カツオ、ご期待ください
suneo3476
0
150
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
150
APNsからLive Activityを開始する話
yumnumm
0
150
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
120
SREの越境 / SRE Collaboration
y0hgi
2
300
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
450
AWSに止められる覚悟してますか?
morizo_1984
2
510
Simple Storage Service(S3) is not simple
iwatsukayura
0
200
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
The Invisible Side of Design
smashingmag
301
52k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
910
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
320
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
300
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
460
Embracing the Ebb and Flow
colly
88
5.2k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Transcript
5分で tRPCに入門する 2022/10/27 @purp1eeeee
自己紹介 むらさき - 株式会社HRBrainのソフトウェアエンジニア - TypeScript/React/Go - TwitterとGitHub: purp1eeeee
tRPCとは
tRPCとは - TypeScriptに特化したHTTP通信ライブラリ - スキーマを書いたりコード生成をする必要がない - エンドポイントの実装からapi clientの型を生成する - サーバーとクライアント間で型を共有する
- monorepoと相性が良い - Next.jsのAPI Routesも
tRPC入門 登場人物 - next 13.0.0 - react 18.2.0 - react-dom
18.2.0 - @trpc/server - @trpc/client - @trpc/next - @trpc/react-query - @tanstack/react-query - zod
tRPC入門 エンドポイントの定義 /server/trpc.ts 最初にtRPCの初期化とユーティリティをexportするエントリーファイルを準備
tRPC入門 エンドポイントの定義 /pages/api/trpc/[trpc].ts request bodyなどはzodやyupなどで定義する それぞれのqueryやmutationに渡すcallback内で DBへのアクセスや加工を行う 25行目のAppRouterがポイントで、この型をclient にジェネリクスとして渡すことで型安全を保証する
tRPC入門 クライアントの定義 /utils/trpc.ts エンドポイントの指定やloggerの様な middleware、カスタムヘッダーや CORSの設定をする /pages/_app.tsx trpcが内部でreact-queryのhook を生成するためprovider対応の ためHOCを行う
tRPC入門 APIを叩いてみる /pages/index.tsx trpcが生成しているhookを呼ぶ 引数や返り値は全て型推論が効いて いる
tRPC入門 APIを叩いてみる
まとめ - 少ない記述で型安全なAPI間やりとりを実現できる - Next.jsと相性が良さそう - 認証認可やエラー処理も試したい 最終形はこちら:https://github.com/purp1eeeee/trpc-practice