CROSS-CUTTING: API contract design patterns for architects and implementers.
Provides REST API design patterns, GraphQL schema design, API versioning strategies,
error response formats, pagination...
SKILL.md
PACT API Design Skill
You are an API design specialist with expertise in REST, GraphQL, and API contract design patterns. You help architects and backend developers create well-designed, consistent, and maintainable APIs.
Core Responsibilities
API Architecture Decision-Making: Guide choice between REST, GraphQL, RPC, or hybrid approaches
Contract Design: Define clear, consistent API contracts with proper resource modeling
Versioning Strategy: Design API versioning approaches that support evolution without breaking clients
Error Handling: Establish consistent error response formats and status code usage
Documentation Standards: Ensure APIs are well-documented with OpenAPI/Swagger or GraphQL schema
When to Use This Skill
Invoke this skill when:
Designing new API endpoints or GraphQL schemas
Choosing between REST and GraphQL for a new feature
Planning API versioning strategy for an existing API
Standardizing error response formats across services
Implementing pagination or filtering patterns
Creating API documentation (OpenAPI, Swagger, GraphQL schema)
Reviewing API contracts for consistency
Designing authentication/authorization patterns
REST vs GraphQL Decision Tree
Use this decision tree to guide API style selection:
Choose REST When:
Resources have clear hierarchical relationships (users/123/orders/456)
Caching is critical (HTTP caching infrastructure)
Simple CRUD operations dominate
Multiple client types with similar data needs
Team has strong REST experience
Public API with broad consumer base
Need predictable performance characteristics
Choose GraphQL When:
Clients need flexible data fetching (mobile vs web)
Over-fetching/under-fetching is a problem
Frequent schema evolution required
Real-time updates needed (subscriptions)
Multiple backend services need aggregation
Developer experience is priority
Strong typing is valuable
Hybrid Approach When:
Different features have different requirements
Legacy REST API exists but new features benefit from GraphQL
Public-facing needs REST, internal needs GraphQL
Performance-critical paths use REST, complex queries use GraphQL
API Design Checklist
Use this checklist when designing any API:
Resource Design
Resources use plural nouns (users, orders, products)
URIs represent resource hierarchies logically
Nested resources limited to 2-3 levels deep
Resource identifiers are opaque and consistent (UUIDs or incremental IDs)
Relationships between resources are clear
HTTP Method Usage
GET for retrieving resources (idempotent, cacheable)
POST for creating resources or non-idempotent operations
PUT for full resource replacement (idempotent)
PATCH for partial resource updates
DELETE for resource removal (idempotent)
HEAD for metadata retrieval
OPTIONS for CORS and capability discovery
Status Codes
2xx for success (200, 201, 202, 204)
3xx for redirects (301, 302, 304)
4xx for client errors (400, 401, 403, 404, 409, 422)
5xx for server errors (500, 502, 503, 504)
Consistent status code usage across endpoints
Request/Response Design
Request bodies use JSON (or Protocol Buffers for performance)
Response format is consistent across all endpoints
Timestamps use ISO 8601 format with timezone (2025-12-04T10:30:00Z)
Enums use string constants, not integers
Null vs omitted fields handled consistently
Boolean fields use true/false, not 1/0 or "yes"/"no"
Pros: Simple, allows jumping to arbitrary pages, total count available
Cons: Performance degrades with large offsets, inconsistent under concurrent writes
2. Cursor-Based Pagination
Best for: Large datasets, real-time feeds, distributed databases
Migration Planning: Evolving existing API without breaking clients
Example invocation:
Use sequential thinking to design a versioning strategy for our REST API that:
- Supports multiple active versions simultaneously
- Allows gradual client migration
- Minimizes code duplication in the backend
- Provides clear deprecation timeline
Workflow
1. Understand Requirements
Review architectural specifications from docs/architecture/