一键导入
api-patterns
API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Senior agent organizer with expertise in assembling and coordinating multi-agent teams. Your focus spans task analysis, agent capability mapping, workflow design, and team optimization.
AI agent design principles. Agent loops, tool calling, memory architectures, multi-agent coordination, human-in-the-loop gates, and guardrails. Use when building AI agents, autonomous workflows, or any system where an LLM plans and executes multi-step tasks.
Main application building orchestrator. Creates full-stack applications from natural language requests. Determines project type, selects tech stack, coordinates agents.
Architectural decision-making framework. Requirements analysis, trade-off evaluation, ADR documentation. Use when making architecture decisions or analyzing system design.
Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.
AI operational modes (brainstorm, implement, debug, review, teach, ship, orchestrate). Use to adapt behavior based on task type.
| name | api-patterns |
| description | API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination. |
| allowed-tools | Read, Write, Edit, Glob, Grep |
| version | 1.0.0 |
| last-updated | "2026-03-12T00:00:00.000Z" |
| applies-to-model | gemini-2.5-pro, claude-3-7-sonnet |
Build APIs that serve their consumers — not APIs that match the tutorial you read last. Every decision here has a trade-off. Know the trade-off before you pick a side.
Only read the files you actually need for this task. The map below tells you where to look.
| File | What It Covers | Load When |
|---|---|---|
api-style.md | Choosing between REST, GraphQL, and tRPC | Client type is unclear or debated |
rest.md | Endpoint naming, HTTP verbs, status code semantics | Building a REST surface |
response.md | Unified response envelope, error shapes, cursor pagination | Defining response contracts |
graphql.md | Schema-first design, N+1 awareness, when NOT to use GraphQL | GraphQL is on the table |
trpc.md | Type-safe RPC for TypeScript monorepos | Full-stack TypeScript project |
versioning.md | URI, header, and content-type versioning strategies | API needs to evolve without breaking clients |
auth.md | JWT, OAuth 2.0, Passkeys, API keys — picking the right one | Authentication is being designed |
rate-limiting.md | Token bucket vs sliding window, burst handling | Protecting public or high-traffic endpoints |
documentation.md | OpenAPI spec quality, example-driven docs | API is being documented |
security-testing.md | OWASP API Top 10, authorization boundary testing | Security review |
| If You Also Need | Load This |
|---|---|
| Server implementation | @[skills/nodejs-best-practices] |
| Data layer | @[skills/database-design] |
| Vulnerability review | @[skills/vulnerability-scanner] |
Answer these before writing a single route:
Patterns that cause pain later:
/getUser, /deleteItem) — REST resources are nounsWhat good looks like:
SSE (Server-Sent Events) — use for AI text streaming:
✅ One-directional: server → client (exactly what LLM streaming is)
✅ HTTP/2-native, works through all proxies
✅ No library needed — native EventSource API in browsers
❌ If the client also needs to send data mid-stream → WebSocket instead
WebSocket — use for bidirectional real-time:
✅ Full-duplex (both directions)
✅ Real-time collaboration, chat, game state
❌ More complex lifecycle management
// ✅ SSE endpoint for AI streaming response
app.get('/api/generate', async (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
const stream = await openai.chat.completions.create({ ..., stream: true });
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content ?? '';
if (text) res.write(`data: ${JSON.stringify({ text })}\n\n`);
}
res.write('data: [DONE]\n\n');
res.end();
});
MCP is the emerging standard (2025) for AI models to interface with external tools and data sources:
// MCP server — expose your API's capabilities as MCP tools
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
const server = new McpServer({ name: 'my-api', version: '1.0.0' });
// Register a tool that AI agents can call
server.tool(
'search_products',
'Search the product catalog by keyword and category',
{
query: z.string().describe('Search terms'),
category: z.string().optional().describe('Filter by category'),
},
async ({ query, category }) => {
const results = await db.searchProducts(query, category);
return { content: [{ type: 'text', text: JSON.stringify(results) }] };
}
);
LLM requests can be expensive. If a client retries due to a timeout, you may charge twice:
// ✅ Idempotency key — same key = return cached response
app.post('/api/generate', async (req, res) => {
const idempotencyKey = req.headers['idempotency-key'];
if (idempotencyKey) {
const cached = await cache.get(`llm:${idempotencyKey}`);
if (cached) return res.json(cached);
}
const result = await callLLM(req.body);
if (idempotencyKey) {
await cache.set(`llm:${idempotencyKey}`, result, { ex: 3600 }); // 1hr TTL
}
res.json(result);
});
| Script | Purpose | Run With |
|---|---|---|
scripts/api_validator.py | Validates endpoint naming and response shape consistency | python scripts/api_validator.py <project_path> |
When this skill produces a recommendation or design decision, structure your output as:
━━━ Api Patterns Recommendation ━━━━━━━━━━━━━━━━
Decision: [what was chosen / proposed]
Rationale: [why — one concise line]
Trade-offs: [what is consciously accepted]
Next action: [concrete next step for the user]
─────────────────────────────────────────────────
Pre-Flight: ✅ All checks passed
or ❌ [blocking item that must be resolved first]
Slash command: /tribunal-backend
Active reviewers: logic · security · dependency
GET /users) without limits or cursors.Review these questions before generating API design or code:
✅ Are all inputs validated at the boundary?
✅ Does every endpoint have an explicit authentication AND authorization check?
✅ Did I use the correct HTTP verbs and semantic status codes?
✅ Is the response shape consistent with the rest of the API?
✅ Did I handle pagination for lists and rate limiting for public endpoints?
AI coding assistants often fall into specific bad habits when dealing with this domain. These are strictly forbidden:
// VERIFY or check package.json / requirements.txt.Slash command: /review or /tribunal-full
Active reviewers: logic-reviewer · security-auditor
// VERIFY: [reason].Review these questions before confirming output:
✅ Did I rely ONLY on real, verified tools and methods?
✅ Is this solution appropriately scoped to the user's constraints?
✅ Did I handle potential failure modes and edge cases?
✅ Have I avoided generic boilerplate that doesn't add value?
CRITICAL: You must follow a strict "evidence-based closeout" state machine.