Skip to content
所有標籤

#api-contract

8 篇文章

GraphQL 與 Code Generator:型別安全來自 schema 加 operation,不只 schema

GraphQL schema 定義可查詢能力;GraphQL Code Generator 再結合實際 query、mutation、fragment,產生精確 result、variables 與 typed document。

gRPC 與 Connect:同一份 Protobuf 合約如何跨服務與瀏覽器

gRPC 以 Protobuf service 產生跨語言 stub;Connect server 可同時支援 gRPC、gRPC-Web 與 Connect protocol,讓瀏覽器不必額外翻譯 proxy。

Hono RPC:從 route implementation 推導 Fetch client 型別

Hono RPC 匯出 route 的 `typeof AppType`,讓 `hc` client 推導 input、response body 與 status code;它共享的是 TypeScript type,不是獨立 wire schema。

oRPC:把 end-to-end type safety 與 OpenAPI 放在同一條路徑

oRPC 同時支援 implementation-first 與 contract-first,能用 RPC client,也能由同一個 router 服務 OpenAPI 3.1.1 HTTP endpoint。

Protobuf 與 Buf:把跨語言 schema 的 lint、codegen 與相容性放進 CI

Protobuf 用穩定 field number 定義 binary message;Buf 補上 module、lint、remote plugin、generation 與 breaking-change check,讓 schema 能被治理。

tRPC:用 TypeScript inference 連起 client 與 server 的 API 合約

tRPC 讓 client 直接引用 server router 的型別,不需先寫 schema 或產生程式碼;v11 另有 alpha 階段的官方 OpenAPI 3.1 產生器。

ts-rest:保留 REST 語意的 TypeScript contract-first API

ts-rest 用共享 contract 描述 method、path、status code 與 schema,在不產生程式碼的前提下讓 server 與 client 保有端到端型別。

Zodios:用 Zod endpoint definition 建立 Axios 型別安全 client

Zodios 以中央 Zod endpoint definition 驅動 Axios client 的型別、runtime validation 與 alias,也能接 Express 和產生 OpenAPI。