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
型安全RESTで爆速プロトタイピング – Hono RPC実践
Search
tacke
May 27, 2025
Programming
700
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
型安全RESTで爆速プロトタイピング – Hono RPC実践
https://layerx.connpass.com/event/355401/
でのLTスライド
tacke
May 27, 2025
More Decks by tacke
See All by tacke
スモールチームがAmazon Cognitoでコスパよく作るサービス間連携認証
tacke_jp
4
5.7k
Androidエンジニアが抑えておくべきUnicode Emojiの知識 (DroidKaigi 2019) / Unicode Emoji for Android Engineer DroidKaigi09
tacke_jp
12
5k
Parse.comからGCPへ移行した話 ~1年間にわたる脱出プロジェクト~
tacke_jp
2
2.2k
Other Decks in Programming
See All in Programming
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
520
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
110
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
250
App Intentsのビルドプロセスを支える技術
kntkymt
0
490
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2k
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.9k
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
150
Simple Storage Service(S3) is not simple
iwatsukayura
0
120
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
290
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1k
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Mind Mapping
helmedeiros
1
390
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Unsuck your backbone
ammeep
672
58k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
From π to Pie charts
rasagy
1
380
Designing Powerful Visuals for Engaging Learning
tmiket
1
590
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Embracing the Ebb and Flow
colly
88
5.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
500
Transcript
商号等 三井物産デジタル‧アセットマネジメント株式会社 ⾦融商品取引業者 関東財務局⻑(⾦商)第3277号 加⼊協会 ⽇本証券業協会、⼀般社団法⼈ ⽇本投資顧問業協会、⼀般社団法⼈ 第⼆種⾦融商品取引業協会 ©Mitsui & Co.
Digital Asset Management, Ltd. 型安全RESTで爆速プロトタイピング ‒ Hono RPC実践 TS Kaigi 2025 After Night LT 2025.5.27
Who am I? • AI Product Team Manager in MDM
(LayerXから出向) • 社内向け内製 LLM Webアプリ を full TypeScript で開発 • モットー: “Build → Ship → Feedback” を最速ループ • 今⽇のテーマ: そのループを⽀える Hono RPC 2 武市 融紀 (X: @tacke_jp)
The “API-Typing” Problem • フロント ↔ サーバー間は ただの JSON •
🛑 型がない → 仕様 drift / runtime error • 既存解 ◦ gRPC ▶ readable じゃない ◦ tRPC ▶ JSON が独特 ◦ GraphQL / JSON-RPC ▶ 汎⽤だけど over-spec • 欲しいのは: ⼈間が読める REST + TypeScript 型安全 3
Landscape Quick Scan 4 ⽅式 プロトコル∕ペイロード 読みやすさ コード⽣成 gRPC HTTP/2,
ProtoBuf 😵 必要 GraphQL POST 1本 😐 (スキーマ必要) tRPC JSON-RPC 😐 不要 Hono RPC 純REST 😀 不要
Enter Hono RPC • Hono: 超軽量Webアプリケーションフレームワーク (24k stars) • RPC
機能 ◦ export type AppType = typeof app → hc<AppType>() だけ ◦ コード⽣成ゼロで型を共有 5 RESTful JSON に 型 をのせる コード⽣成 0, Hot-reload 100%を実現
How it Works // server.ts const route = app .post(
'/posts', zValidator('json', z.object({ title: z.string(), body: z.string(), })), (c) => c.json({ ok: true, message: 'Created!', }, 201) ) export type AppType = typeof route 6 // client.ts import { hc } from 'hono/client' import type { AppType } from '../server' const client = hc< AppType>('/api') const res = await client.posts.$post({ json: { title: 'Hello', body: 'Hono RPC is cool', }, }) // data: { ok: boolean; message: string } const data = await res.json()
✨ What I Like • 普通の REST + 強い型 =
学習コストほぼゼロ • 変更 → 即 red-squiggle (tRPC 同等体験) • ルート毎に HTTP ステータス × 型 を区別可 • 型安全だから UI <-> API 断絶を防⽌ 7
⚠ Caveats / Gotchas in Practice • full-TS プロジェクト限定 •
ミドルウェア経由の Response型は 現状推論されない • 複雑な型は IDE 上で … 折り畳まれる ◦ Tips: 末端 hover ∕ c.json<Foo>() のように明⽰型を付ける • ルータは method chain で書かないと推論が途切れる ◦ 公式ドキュメントでも⾮RPC部分の例はchainしていないので Coding Agentが引っ張られがち 8
⚠ Caveats / Gotchas in Practice (2) // ❌ NG:
各ハンドラを後から繋げる const app = new Hono() app.get('/hello', (c) => c.json({ msg: 'hi' })) app.post('/hello', (c) => c.json({ ok: true })) export type AppType = typeof app // ←推論されない! 9 // ✅ OK: chain してから変数に束ねる const route = new Hono() .get('/hello', (c) => c.json({ msg: 'hi' })) .post('/hello', (c) => c.json({ ok: true })) export type AppType = typeof route // works
Case Study: “Copilot” for ファンド契約書 • pnpm workspaceで web (Next.js)
と backend (Hono API server) を分離 ◦ api で export type AppType → web で hc<AppType>() • SWR + Hono Client = 型安全 Data Fetching • API で { success: true | false } union を返す ◦ UI 側で toast 必須チェック を静的解析 • cookieAuth middleware は new Hono<{ Variables: AuthUser }>() で推 論注⼊ 10
まとめ • REST 可読性 × 型安全 × 開発速度 = Hono
RPC • プロトタイピング勢‧Edge Deploy 勢に特におすすめ • 試したくなったら 👉 pnpm add hono @hono/zod-validator 11
コーポレートサイト https://corp.mitsui-x.com/ サービスサイト(ALTERNA) https://alterna-z.com/