api-design

Guidance for designing HTTP and REST interfaces: web endpoints that use standard HTTP methods to create, read, update, and delete resources.

In plain words
What is it for?
Use it when creating or changing endpoints, deciding whether a change is backward-incompatible, connecting frontend and backend work, or reviewing inconsistent API designs.
Why use it?
It helps keep URLs, status codes, versions, and error responses consistent, so clients and monitoring tools can interpret the API correctly.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/wade-devcode/awesome-coding-skills-cn/api-design
Any agent
npx skills add Wade-DevCode/awesome-coding-skills-cn --skill api-design
Clone the repo
git clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cn

Made for: Claude Code, Codex.

Per session 26 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,508 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00026 $0.02508
Opus 5 $0.00013 $0.01254
Sonnet 5 $0.00005 $0.00502
Haiku 4.5 $0.00003 $0.00251

Measured 2d ago against content hash 2ab6a1d119f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-design scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/api-design/SKILL.md · 187 lines

How it starts

The opening of the file, as written. The whole thing — 187 lines — stays where its author put it; the contents beside it link to each section on GitHub.

接口设计

何时用

  • 新增 HTTP/REST 接口,需要确定 URL 路径、请求体与响应结构时。
  • 修改已有接口,要评估是否属于破坏性变更、是否需要新版本时。
  • 联调阶段前端反馈"不知道错误含义"或"状态码对不上"时。
  • code review 发现接口风格混乱,需要统一约定时。

核心规则

1. 资源用名词复数,HTTP 方法表达动作

规则: URL 只描述资源,增删改查全靠 HTTP 方法(GET/POST/PUT/PATCH/DELETE)区分,禁止在路径里塞动词。

为什么: AI 生成代码时极容易把动作写进路径——POST /createUserGET /getUserByIdPOST /deleteOrder。这样做破坏了 REST 的统一接口约束:客户端无法通过方法推断语义,反向代理的缓存/日志规则也按 HTTP 方法设计,动词 URL 会绕开这些设施。积累下来接口命名五花八门,新人一眼看不懂哪个是幂等的、哪个有副作用。

怎么做:

  • 集合资源用复数:/users/orders/products/{id}/reviews
  • 子资源层级不超过三级:/users/{uid}/addresses/{aid} 可接受,再深就拍平。
  • 真正的「动作」(非 CRUD)用子资源或 action 后缀:POST /orders/{id}/cancelPOST /payments/{id}/refund,不要 POST /cancelOrder

2. 状态码严格对应语义

规则: 按 HTTP 语义选状态码:2xx 成功、4xx 客户端的错、5xx 服务端的错;不用"一律 200 + { "code": 500 } "的私有协议。

为什么: AI 生成的服务端代码极常见"全部返回 200,用 body 里的 code 表示真实状态"——看起来简单,实则让所有上层基础设施失效:Nginx 的 5xx 告警触发不了,监控平台抓不到真实错误率,HTTP 客户端的重试/熔断逻辑按 2xx 判定成功而放行所有故障流量。出了事故查日志,全是绿的。

怎么做:

  • 200 成功返回资源,201 创建成功(带 Location 头),204 成功但无响应体(DELETE)。
  • 400 请求格式/参数错误,401 未认证,403 无权限(已认证但拒绝),404 资源不存在,409 冲突(重复创建),422 业务校验失败。
  • 500 服务内部错误,502/503 上游/服务不可用,504 超时。
  • 不要用 200 返回错误信息,也不要用 500 返回校验失败。

3. 错误响应结构统一,前端可程序化处理

规则: 所有错误响应用相同结构:code(机器可读的错误标识)、message(人类可读说明)、details(可选,字段级明细),不能每个接口各自为政。

为什么: AI 最容易犯的错是:有的接口报错返回 {"error": "invalid email"},有的返回 {"msg": "用户不存在"},有的直接丢出框架的原始异常 JSON。前端被迫为每个接口写专属错误解析逻辑,错误提示文案散落各处。哪天要做统一的错误埋点或国际化,根本没有抓手。

怎么做:

{
  "code": "VALIDATION_ERROR",
  "message": "请求参数不合法",
  "details": [
    { "field": "email", "message": "邮箱格式不正确" },
    { "field": "age",   "message": "年龄必须大于 0" }
  ]
}
  • codeSCREAMING_SNAKE_CASE 枚举值,前端可 switch/map 处理。
  • message 面向开发者,不直接作为用户提示(i18n 由前端按 code 查表)。
  • details 仅在有字段级信息时出现,表单校验必带。

4. 破坏性变更走版本号

规则: 接口路径加 /v1/v2 前缀;不兼容的改动新开版本,旧版本保留至少一个过渡期,不在原路径上直接覆盖。

为什么: AI 修改接口时惯于"直接改字段名"或"删除旧字段"——测试环境跑通了,但已上线的移动端 App、第三方集成、还没发版的前端全部一起炸。破坏性变更无声地推出去,只有故障告警才会被发现,而此时回滚服务端又会打烂已经发版的新客户端。

Read the full file on GitHub · 187 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 187 lines · 26 tokens per session scan A 2ab6a1d119f5

Subscribe to this mod's changes

api-design is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (6 stars, last pushed 2mo ago), licensed MIT. It adds 26 tokens to every session and 2,508 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

chinese-git-workflow

国内 Git 平台配置参考——Gitee、Coding.net、极狐 GitLab、CNB 的 SSH/HTTPS/凭据/CI 接入差异与镜像同步配置。仅在用户显式 /chinese-git-workflow 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 69 tokens

brainstorming

在任何创造性工作之前必须使用此技能——创建功能、构建组件、添加功能或修改行为。在实现之前先探索用户意图、需求和设计。.

jnMetaCode/superpowers-zh · 40 tokens

chinese-code-review

中文 review 沟通参考——话术模板、分级标注(必须修复/建议修改/仅供参考)、国内团队常见反模式应对。仅在用户显式 /chinese-code-review 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 62 tokens

chinese-commit-conventions

中文 commit 与 changelog 配置参考——Conventional Commits 中文适配、commitlint/husky/commitizen 中文模板、conventional-changelog 中文配置。仅在用户显式 /chinese-commit-conventions 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 65 tokens

chinese-documentation

中文文档排版参考——中英文空格、全半角标点、术语保留、链接格式、中文文案排版指北约定。仅在用户显式 /chinese-documentation 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 62 tokens

systematic-debugging

Skill "systematic-debugging" from jnMetaCode/superpowers-zh, covering 系统化调试, 概述, 铁律, 何时使用 and 四个阶段.

jnMetaCode/superpowers-zh · 24 tokens