跳到正文
cccskills
免费在 GitHub 公开

api-design-principles

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(6)

  • SKILL.md4.7 KB
  • assets/api-design-checklist.md3.8 KB
  • assets/rest-api-template.py5.2 KB
  • references/graphql-schema-design.md8.8 KB
  • references/rest-best-practices.md7.4 KB
  • resources/implementation-playbook.md12.7 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

API Design Principles

Design APIs that developers love to use — consistent, predictable, and well-documented.

When to Use

  • Designing new REST or GraphQL APIs
  • Reviewing API specs before implementation
  • Establishing API design standards for a team
  • Migrating between API paradigms

When NOT to Use

  • Framework-specific implementation details (use stack skills instead)
  • Infrastructure-only work without API contracts
  • Existing APIs that cannot be versioned

Core Rules

1. Resources Are Nouns, Methods Are Verbs

✅ GET    /api/users          → List users
✅ POST   /api/users          → Create user
✅ GET    /api/users/{id}     → Get user
✅ PATCH  /api/users/{id}     → Update user fields
✅ DELETE /api/users/{id}     → Delete user

❌ POST   /api/createUser
❌ GET    /api/getUserById
❌ POST   /api/deleteUser

2. HTTP Methods Have Meaning

MethodPurposeIdempotentSafeRequest Body
GETRead✅✅No
POSTCreate❌❌Yes
PUTReplace✅❌Yes
PATCHPartial update❌❌Yes
DELETERemove✅❌No

3. Status Codes Tell the Story

CodeWhenExample
200Success with bodyGET returns resource
201CreatedPOST creates new resource
204Success, no bodyDELETE succeeds
400Client sent bad dataMalformed JSON
401Not authenticatedMissing/invalid token
403Authenticated but not authorizedWrong role
404Resource doesn't existInvalid ID
409ConflictDuplicate email
422Valid JSON, invalid contentEmail format wrong
429Rate limitedToo many requests
500Server errorUnhandled exception

4. Error Responses Are Structured

{
  "error": "ValidationError",
  "code": "INVALID_EMAIL",
  "message": "Email address is not valid",
  "details": {
    "field": "email",
    "value": "not-an-email",
    "constraint": "Must be a valid email format"
  }
}

Rules:

  • Same envelope for every error
  • Machine-readable code for client logic
  • Human-readable message for display
  • details for field-level validation errors
  • NEVER include stack traces in production

5. Always Paginate Collections

GET /api/users?page=2&page_size=20

Response:
{
  "items": [...],
  "total": 243,
  "page": 2,
  "page_size": 20,
  "pages": 13
}

For GraphQL, use cursor-based pagination (Relay spec):

type UserConnection {
  edges: [UserEdge!]!
  pageInfo: PageInfo!
  totalCount: Int!
}

6. Version From Day One

StrategyURLHeaderQuery
Example/api/v1/usersAccept: application/vnd.api+json; version=1/api/users?version=1
ProsSimple, visibleClean URLsSimple to add
ConsURL pollutionHidden from browsersCaching complexity
Best forMost APIsInternal APIsQuick prototypes

7. Rate Limit Everything Public

Every public endpoint must return rate limit headers:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 42
X-RateLimit-Reset: 1625097600

API Design Checklist

Before implementing any endpoint:

  • Resource name is a plural noun
  • HTTP method matches the operation semantics
  • Request/response schemas are defined (contract-first)
  • Error responses use consistent envelope
  • Pagination is implemented for collection endpoints
  • Authentication and authorization rules are specified
  • Rate limiting is configured
  • API version is specified
  • Input validation rules are documented per field

Anti-Patterns

Don'tDo
Verbs in URLs (/getUser)Nouns + HTTP methods (GET /users)
200 for everythingCorrect status codes per operation
Generic errors ("Something went wrong")Structured errors with codes
Return all fields alwaysSupport field selection or use GraphQL
Nest resources >2 levels deep/users/{id}/orders max; flatten after that
Ignore backward compatibilityVersion APIs; deprecation headers before removal

Extended Reference

See resources/implementation-playbook.md for:

  • Full pagination implementation (FastAPI)
  • HATEOAS patterns
  • GraphQL schema design with Relay-style connections
  • DataLoader patterns for N+1 prevention
  • Complete code templates

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Audit and improve web accessibility following WCAG 2.1 guidelines. Use when asked to "improve accessibility", "a11y audit", "WCAG compliance", "screen reader support", "keyboard navigation", or "make accessible".

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Structured methodology for adversarial thinking — generating attack scenarios, abuse cases, race conditions, and security edge cases against specs and implementations. Produces spec-level gap items, not code-level fixes.

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Orchestrate multiple Antigravity skills through guided workflows for SaaS MVP delivery, security audits, AI agent builds, and browser QA.

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Manage API versioning and evolution with URL/header/query strategies, deprecation workflows, breaking change classification, sunset headers, and consumer-driven contract testing. Use when designing versioning strategy, deprecating endpoints, or evolving API contracts.

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Analyzes codebase structure, data flow, module relationships, and key patterns to generate and maintain a living architecture document (ARCHITECTURE.md).

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Orchestrate ambiguity auditing across selected layers with rubric-driven scoring, remediation flow, and next-step gating

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

查看 RepairYourTech 的全部技能

报告此技能的问题