本文へ移動
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(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

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

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

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 のスキルをすべて見る

このスキルの問題を報告する