业务 API 建模
按业务模块组织 userApi、orderApi 等稳定入口,不让 URL 和请求细节散落在页面中。
Backend API
↓
Service
↓
Business API
↓
业务代码Service 定义服务边界,业务 API 表达具体业务能力:
await userApi.list({ page: 1 })
await orderApi.submit(data)业务代码无需重复拼接地址,也无需为每个页面重复处理相同的请求规则。
Codegen 是 API 建模的辅助工具,生成的仍然是同一种业务 API:
OpenAPI → API Codegen → TypeScript 类型 + Business API先从 介绍 理解模型,或在已有 OpenAPI 时查看 API Codegen。