skills/api-design-ops/SKILL.md
API design patterns for REST, gRPC, and GraphQL. Use for: api design, REST, gRPC, GraphQL, protobuf, schema design, api versioning, pagination, rate limiting, error format, OpenAPI, API authentication, JWT, OAuth2, API gateway, webhook, idempotency.
npx skillsauth add 0xDarkMatter/claude-mods api-design-opsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Comprehensive API design patterns covering REST (advanced), gRPC, and GraphQL. This skill provides decision frameworks, design patterns, and implementation guidance for building production APIs.
What kind of API do you need?
|
+-- Internal microservice-to-microservice?
| +-- High throughput, low latency needed? --> gRPC
| +-- Streaming (real-time data, logs)? --> gRPC (bidirectional streaming)
| +-- Simple request/response, team comfort? --> REST
|
+-- Public-facing API?
| +-- Third-party developers consuming it? --> REST (widest compatibility)
| +-- Mobile app with varied data needs? --> GraphQL
| +-- Browser-only, simple CRUD? --> REST
|
+-- Frontend for your own app?
| +-- Multiple clients with different data shapes? --> GraphQL
| +-- Single client, straightforward data? --> REST
| +-- Real-time updates needed? --> GraphQL subscriptions or SSE
|
+-- IoT / embedded / constrained devices?
| +-- Binary efficiency matters? --> gRPC
| +-- HTTP-only environments? --> REST
| Concern | REST | gRPC | GraphQL | |---------|------|------|---------| | Transport | HTTP/1.1+ | HTTP/2 | HTTP (any) | | Serialization | JSON (text) | Protobuf (binary) | JSON (text) | | Schema | OpenAPI (optional) | .proto (required) | SDL (required) | | Browser support | Native | Via gRPC-Web/Connect | Native | | Caching | HTTP caching built-in | Custom | Custom (normalized) | | Learning curve | Low | Medium | Medium-High | | Code generation | Optional | Required | Optional but recommended | | Streaming | SSE, WebSocket | Native (4 patterns) | Subscriptions | | Over-fetching | Common problem | No (typed) | Solved by design | | File uploads | Multipart native | Chunked streaming | Multipart spec (awkward) |
GET /users # Collection
GET /users/{id} # Singleton
GET /users/{id}/orders # Sub-collection
POST /users # Create
PUT /users/{id} # Full replace
PATCH /users/{id} # Partial update
DELETE /users/{id} # Remove
# Naming rules:
# - Plural nouns for collections: /users NOT /user
# - Kebab-case for multi-word: /line-items NOT /lineItems
# - No verbs in URLs: POST /orders NOT POST /create-order
# - Max 3 levels deep: /users/{id}/orders (not /users/{id}/orders/{oid}/items/{iid}/details)
| Method | Success | Empty | Invalid | Not Found | Conflict | |--------|---------|-------|---------|-----------|----------| | GET | 200 | 200 (empty array) | 400 | 404 | - | | POST | 201 + Location | - | 400/422 | - | 409 | | PUT | 200 | - | 400/422 | 404 | 409 | | PATCH | 200 | - | 400/422 | 404 | 409 | | DELETE | 204 | 204 (already gone) | 400 | 404 | 409 |
Use when: public APIs where discoverability matters, long-lived APIs, APIs that evolve frequently. Skip when: internal microservices, mobile backends, tight coupling is acceptable.
{
"id": "order-123",
"status": "shipped",
"_links": {
"self": { "href": "/orders/order-123" },
"track": { "href": "/orders/order-123/tracking" },
"cancel": { "href": "/orders/order-123", "method": "DELETE" }
}
}
What's your data like?
|
+-- Stable data, UI needs "jump to page 5"?
| --> Offset pagination: ?page=5&per_page=20
| Tradeoff: Slow on large offsets (OFFSET 10000), inconsistent with inserts
|
+-- Large dataset, forward-only traversal?
| --> Cursor pagination: ?after=eyJpZCI6MTIzfQ&limit=20
| Tradeoff: No random page access, but consistent and fast
|
+-- Real-time feed, ordered by timestamp or ID?
| --> Keyset pagination: ?created_after=2024-01-01T00:00:00Z&limit=20
| Tradeoff: Requires a unique, sequential column; no page jumping
{
"data": [...],
"pagination": {
"total": 1432,
"limit": 20,
"has_more": true,
"next_cursor": "eyJpZCI6MTQzMn0="
}
}
All APIs should use Problem Details (RFC 7807 / RFC 9457):
{
"type": "https://api.example.com/errors/insufficient-funds",
"title": "Insufficient Funds",
"status": 422,
"detail": "Account xxxx-1234 has a balance of $10.00, but the transfer requires $25.00.",
"instance": "/transfers/txn-abc-123",
"balance": 1000,
"required": 2500
}
| Field | Required | Description |
|-------|----------|-------------|
| type | Yes | URI identifying the error type (stable, documentable) |
| title | Yes | Human-readable summary (same for all instances of this type) |
| status | Yes | HTTP status code |
| detail | Yes | Human-readable explanation specific to this occurrence |
| instance | No | URI identifying the specific occurrence |
| (extensions) | No | Additional machine-readable fields |
{
"type": "https://api.example.com/errors/validation",
"title": "Validation Failed",
"status": 422,
"detail": "The request body contains 2 validation errors.",
"errors": [
{ "field": "email", "message": "Must be a valid email address", "code": "invalid_format" },
{ "field": "age", "message": "Must be at least 18", "code": "out_of_range", "min": 18 }
]
}
| Strategy | Example | Pros | Cons |
|----------|---------|------|------|
| URL path | /v2/users | Obvious, cacheable, easy routing | URL pollution, hard to sunset |
| Accept header | Accept: application/vnd.api.v2+json | Clean URLs, content negotiation | Hidden, harder to test |
| Query param | /users?version=2 | Easy to add | Pollutes query string, caching issues |
| Date-based | API-Version: 2024-01-15 | Granular evolution (Stripe style) | Complex implementation |
/v1/) - simplicity winsA breaking change is anything that can cause existing clients to fail:
Non-breaking (safe):
| Algorithm | Behavior | Use When | |-----------|----------|----------| | Token bucket | Allows bursts, refills at steady rate | General API rate limiting | | Sliding window | Smooth distribution, no burst | Strict fairness needed | | Fixed window | Simple, potential burst at boundary | Low-stakes limiting | | Leaky bucket | Constant output rate | Queue processing |
X-RateLimit-Limit: 1000 # Max requests per window
X-RateLimit-Remaining: 743 # Requests left in current window
X-RateLimit-Reset: 1672531200 # Unix timestamp when window resets
Retry-After: 30 # Seconds to wait (on 429)
{
"type": "https://api.example.com/errors/rate-limit-exceeded",
"title": "Rate Limit Exceeded",
"status": 429,
"detail": "You have exceeded 1000 requests per hour. Try again in 30 seconds.",
"retry_after": 30
}
| Method | Idempotent by spec? | Needs key? | |--------|---------------------|------------| | GET | Yes | No | | PUT | Yes | No (full replacement is naturally idempotent) | | DELETE | Yes | No | | PATCH | No | Recommended for critical operations | | POST | No | Yes (always for payments, orders, transfers) |
POST /payments
Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000
Content-Type: application/json
{ "amount": 2500, "currency": "usd", "customer": "cust_123" }
Server-side:
Idempotency-Key header| Method | Use When | Security Level | |--------|----------|----------------| | API Key | Server-to-server, internal, simple | Low-Medium | | JWT (Bearer) | Stateless auth, microservices | Medium-High | | OAuth2 + PKCE | Third-party access, user delegation | High | | mTLS | Service mesh, zero-trust infra | Very High |
Who is authenticating?
|
+-- Your own frontend? --> JWT (short-lived access + refresh token)
+-- Third-party developer? --> OAuth2 (client credentials for server, PKCE for SPA)
+-- Another internal service? --> mTLS or JWT with service accounts
+-- Quick prototype? --> API key (but plan migration)
| Gotcha | Problem | Prevention |
|--------|---------|------------|
| Breaking changes in "non-breaking" release | Client crashes | Additive-only policy, contract tests |
| N+1 in REST APIs | 100 users = 101 queries | Compound documents, ?include=, or GraphQL |
| Over-fetching | Mobile gets 50 fields, needs 3 | Sparse fieldsets ?fields=id,name or GraphQL |
| Under-fetching | 3 requests to build one view | Composite endpoints or BFF pattern |
| CORS misconfiguration | Frontend can't reach API | Explicit allowed origins, never * with credentials |
| Missing Content-Type | 415 or silent parsing failure | Validate Content-Type on every mutation endpoint |
| Large payloads without pagination | OOM, timeouts | Always paginate collections, set max page size |
| Inconsistent date formats | Parsing hell | ISO 8601 everywhere: 2024-01-15T10:30:00Z |
| No request IDs | Impossible to debug | Generate X-Request-ID, propagate through services |
| Enum evolution | New value breaks old client | Document that enums may grow, clients must handle unknown |
| Missing idempotency | Duplicate charges, orders | Idempotency keys on all POST endpoints with side effects |
| Unbounded query complexity | GraphQL DoS | Depth limiting, cost analysis, persisted queries |
| File | Contents |
|------|----------|
| references/rest-advanced.md | Resource modeling, PATCH strategies, caching, webhooks, bulk ops |
| references/grpc.md | Protobuf, service definitions, Go/Rust, streaming, error handling |
| references/graphql.md | Schema design, resolvers, DataLoader, federation, performance |
| references/api-security.md | JWT, OAuth2, CORS, rate limiting, OWASP API Top 10 |
testing
Audit any repo against the agentic-quality doctrine — score entry docs, structure, and enforcement gates, then map each finding to its fix. Triggers on: repo doctor, repo audit, agentic quality, is this repo agent-friendly, doc drift, stale AGENTS.md, monorepo structure, nested CLAUDE.md.
data-ai
Router for parallel or recurring agent work across six skills. Covers: parallel agents, fan out work, delegate to workers, run overnight, scheduled loop, land branches, mixed-model fleet, orchestrate workers, background agents at scale. Triggers on: which skill for parallel work, fan out agents, spawn workers, run this overnight, schedule a loop, land my branches, heterogeneous fleet, delegate to cheaper model, autonomous loop.
tools
Heterogeneous cross-provider fleet - GLM (z.ai), Codex (OpenAI), Grok (xAI), Anthropic Sonnet/Opus/Haiku - from one session, porting the native Workflow tool's patterns (adversarial verify, judge panels, journal resume) to OS-process workers. Triggers: fleetflow, heterogeneous/mixed-model fleet, codex worker, grok worker, cross-provider fan-out, cross-model verify.
development
Application/game-scale three.js: ES modules, GLTF pipeline (DRACO/KTX2/meshopt), AnimationMixer, physics (rapier/cannon-es), react-three-fiber, and performance at scale (InstancedMesh, LOD, draw calls). Triggers on: three.js, GLTFLoader, r3f, game loop, WebGL memory leak, boids.