api-design
Design or review a REST or GraphQL API — resource modeling, versioning strategy, error contract, OpenAPI/schema-first workflow, and security baseline
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Design or review a REST or GraphQL API — resource modeling, versioning strategy, error contract, OpenAPI/schema-first workflow, and security baseline
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Health check procedures D1–D14 for the Audit agent — structural validation, attention budget, version checks, workspace integrity, and static audit
Configure and manage Model Context Protocol servers for external tool access
Review a UI for accessibility — WCAG 2.1 AA compliance, semantic HTML, ARIA usage, keyboard navigation, focus management, colour contrast, and screen reader compatibility
Generate a CHANGELOG.md entry from staged changes, a commit range, or a PR diff — following Keep a Changelog format with conventional commit classification
Set up and audit environment variable management — create .env.example, add startup validation, separate secrets from config, and document every variable
Generate or update onboarding documentation — README, CONTRIBUTING guide, dev environment setup script, and new-developer validation checklist
| name | api-design |
| description | Design or review a REST or GraphQL API — resource modeling, versioning strategy, error contract, OpenAPI/schema-first workflow, and security baseline |
| compatibility | >=0.7.0 |
Skill metadata: version "1.0"; license MIT; tags [api, rest, graphql, openapi, design]; compatibility ">=0.7.0"; recommended tools [codebase, editFiles, runCommands].
Design a new API or review an existing one for consistency, versioning, security, and documentation. Produces an OpenAPI 3.1 spec or GraphQL schema as the source of truth.
Ask if not obvious:
/v1/), header (Accept-Version), or none?REST — resource identification:
Nouns, not verbs. Collections and items:
GET /orders → list orders
POST /orders → create order
GET /orders/{id} → get order
PATCH /orders/{id} → partial update
DELETE /orders/{id} → delete order
Nested resources only one level deep:
GET /orders/{id}/items ✓
GET /orders/{id}/items/{itemId}/details ✗ (flatten to /order-items/{id})
GraphQL — type-first design:
type Order {
id: ID!
status: OrderStatus!
items: [OrderItem!]!
createdAt: DateTime!
}
type Query {
order(id: ID!): Order
orders(filter: OrderFilter, pagination: PaginationInput): OrderConnection!
}
type Mutation {
createOrder(input: CreateOrderInput!): CreateOrderPayload!
updateOrderStatus(id: ID!, status: OrderStatus!): UpdateOrderPayload!
}
Consistent error responses prevent client surprises.
REST (RFC 7807 Problem Details):
{
"type": "https://api.example.com/errors/validation",
"title": "Validation Error",
"status": 422,
"detail": "The 'email' field must be a valid email address.",
"instance": "/orders/create",
"errors": [
{ "field": "email", "message": "invalid email format" }
]
}
Standard status codes:
200 OK — success with body201 Created — resource created (Location header required)204 No Content — success, no body400 Bad Request — client input error401 Unauthorized — missing/invalid auth403 Forbidden — authenticated but not permitted404 Not Found — resource does not exist409 Conflict — state conflict (e.g., duplicate)422 Unprocessable Entity — validation failure429 Too Many Requests — rate limited (Retry-After header required)500 Internal Server Error — never expose internal detailsGraphQL errors:
{
"errors": [
{
"message": "Order not found",
"extensions": { "code": "NOT_FOUND", "orderId": "abc123" }
}
]
}
Schema-first: write the spec before the implementation.
openapi: "3.1.0"
info:
title: Orders API
version: "1.0.0"
paths:
/orders:
post:
summary: Create an order
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateOrderRequest'
responses:
'201':
description: Order created
headers:
Location:
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'422':
$ref: '#/components/responses/ValidationError'
Validate the spec:
npx @redocly/cli lint openapi.yaml
# or
npx swagger-cli validate openapi.yaml
Every API must have:
| Control | Implementation |
|---|---|
| Authentication | JWT bearer (Authorization: Bearer <token>) or API key |
| HTTPS only | Reject HTTP at load balancer; HSTS header |
| Input validation | Validate all input against schema; reject unknown fields |
| Rate limiting | 429 + Retry-After; per-user and per-IP limits |
| CORS | Allowlist origins; never * for credentialed requests |
| Sensitive data | Never expose passwords, internal IDs, or PII in error messages |
| Strategy | When to use | Trade-off |
|---|---|---|
URL path /v1/ | Public APIs, long-lived | Simple, cacheable; requires routing duplication |
Accept: application/vnd.api+json;version=1 | API-first teams | Clean URL; harder to test in browser |
| No versioning + additive-only policy | Internal APIs, single consumer | Simplest; requires discipline |
Additive-only rule: adding fields, endpoints, and optional parameters is non-breaking. Removing or renaming is always breaking.
cursor or page/limit)redocly lint or swagger-cli validate)