api-design skill
リソース命名、ステータス コード、ページネーション、フィルタリング、エラー応答、バージョン管理、およびレート制限を含む REST API デザイン パターン。
A100/100content scan
Is the api-design skill safe?
Clean: nothing in its files matched our rules. We read 1 file in the folder on 2026-09-28.
No findings.
Install the api-design skill
A skill is a folder. Copy it into your agent's skills folder and the agent loads it when the task matches its description.
git clone --depth 1 https://github.com/affaan-m/ECC.git /tmp/ECC mkdir -p ~/.claude/skills cp -r /tmp/ECC/docs/ja-JP/skills/api-design ~/.claude/skills/api-design
available in every project
In the Claude apps, zip the folder and upload it from the Skills settings. The folder on GitHub
The instructions your agent would load
SKILL.md as published, without the frontmatter. Read it on GitHub
API デザイン パターン
一貫性のある開発者フレンドリーな REST API を設計するための規約とベスト プラクティス。
アクティブ化するとき
- 新しい API エンドポイントを設計しているとき
- 既存の API 契約をレビューしているとき
- ページネーション、フィルタリング、またはソートを追加しているとき
- API のエラー処理を実装しているとき
- API バージョン管理戦略を計画しているとき
- パブリックまたはパートナー向けの API を構築しているとき
リソース デザイン
URL 構造
# リソースは名詞、複数形、小文字、ケバブケース
GET /api/v1/users
GET /api/v1/users/:id
POST /api/v1/users
PUT /api/v1/users/:id
PATCH /api/v1/users/:id
DELETE /api/v1/users/:id
# 関係のための サブ リソース
GET /api/v1/users/:id/orders
POST /api/v1/users/:id/orders
# CRUD にマップされないアクション (動詞は慎重に使用)
POST /api/v1/orders/:id/cancel
POST /api/v1/auth/login
POST /api/v1/auth/refresh命名規則
# よい
/api/v1/team-members # 複数単語リソース用ケバブケース
/api/v1/orders?status=active # フィルタリング用クエリ パラメーター
/api/v1/users/123/orders # 所有権用のネストされたリソース
# 悪い
/api/v1/getUsers # URL 内の動詞
/api/v1/user # 単数形(複数形を使用)
/api/v1/team_members # URL 内のスネークケース
/api/v1/users/123/getOrders # ネストされたリソース内の動詞HTTP メソッドとステータス コード
メソッド セマンティクス
*PATCH は適切な実装でべき等にすることができます
ステータス コード リファレンス
# 成功
200 OK — GET、PUT、PATCH(応答本体付き)
201 Created — POST (Location ヘッダーを含める)
204 No Content — DELETE、PUT(応答本体なし)
# クライアント エラー
400 Bad Request — 検証失敗、不正な JSON
401 Unauthorized — 認証がない、または無効
403 Forbidden — 認証済みですが認可されていない
404 Not Found — リソースが存在しません
409 Conflict — 重複エントリ、状態競合
422 Unprocessable Entity — セマンティック上無効(有効な JSON、悪いデータ)
429 Too Many Requests — レート制限を超過
# サーバー エラー
500 Internal Server Error — 予期しない失敗 (詳細は公開しない)
502 Bad Gateway — アップストリーム サービスが失敗
503 Service Unavailable — 一時的なオーバーロード、Retry-After を含める一般的な間違い
# 悪い: すべてに 200
{ "status": 200, "success": false, "error": "Not found" }
# よい: HTTP ステータス コードをセマンティック的に使用
HTTP/1.1 404 Not Found
{ "error": { "code": "not_found", "message": "User not found" } }
# 悪い: 検証エラーに 500
# よい: フィールドレベルの詳細を含む 400 または 422
# 悪い: 作成されたリソースに 200
# よい: Location ヘッダー付き 201
HTTP/1.1 201 Created
Location: /api/v1/users/abc-123応答フォーマット
成功応答
{
"data": {
"id": "abc-123",
"email": "alice@example.com",
"name": "Alice",
"created_at": "2025-01-15T10:30:00Z"
}
}コレクション応答(ページネーション付き)
{
"data": [
{ "id": "abc-123", "name": "Alice" },
{ "id": "def-456", "name": "Bob" }
],
"meta": {
"total": 142,
"page": 1,
"per_page": 20,
"total_pages": 8
},
"links": {
"self": "/api/v1/users?page=1&per_page=20",
"next": "/api/v1/users?page=2&per_page=20",
"last": "/api/v1/users?page=8&per_page=20"
}
}エラー応答
{
"error": {
"code": "validation_error",
"message": "Request validation failed",
"details": [
{
"field": "email",
"message": "Must be a valid email address",
"code": "invalid_format"
},
{
"field": "age",
"message": "Must be between 0 and 150",
"code": "out_of_range"
}
]
}
}応答エンベロープ バリエーション
// オプション A: データ ラッパー付きエンベロープ(パブリック API に推奨)
interface ApiResponse<T> {
data: T;
meta?: PaginationMeta;
links?: PaginationLinks;
}
interface ApiError {
error: {
code: string;
message: string;
details?: FieldError[];
};
}
// オプション B: フラット応答(シンプル、内部 API 向け)
// 成功: リソースを直接返す
// エラー: エラー オブジェクトを返す
// HTTP ステータス コードで区別ページネーション
オフセット ベース(シンプル)
GET /api/v1/users?page=2&per_page=20
# 実装
SELECT * FROM users
ORDER BY created_at DESC
LIMIT 20 OFFSET 20;長所: 実装が簡単、「N ページにジャンプ」をサポート 短所: 大きなオフセット(OFFSET 100000)で低速、同時挿入で矛盾
カーソル ベース(スケーラブル)
GET /api/v1/users?cursor=eyJpZCI6MTIzfQ&limit=20
# 実装
SELECT * FROM users
WHERE id > :cursor_id
ORDER BY id ASC
LIMIT 21; -- 次が있는지 判定するため 1 つ余分に取得{
"data": [...],
"meta": {
"has_next": true,
"next_cursor": "eyJpZCI6MTQzfQ"
}
}長所: 位置に関わらず一貫性のあるパフォーマンス、同時挿入では安定 短所: 任意のページへのジャンプができない、カーソルが不透明
どちらを使用するか
フィルタリング、ソート、検索
フィルタリング
# シンプルな等価性
GET /api/v1/orders?status=active&customer_id=abc-123
# 比較演算子(括弧表記を使用)
GET /api/v1/products?price[gte]=10&price[lte]=100
GET /api/v1/orders?created_at[after]=2025-01-01
# 複数値(カンマ区切り)
GET /api/v1/products?category=electronics,clothing
# ネストされたフィールド(ドット表記)
GET /api/v1/orders?customer.country=USソート
# 単一フィールド (降順用に - を頭に付ける)
GET /api/v1/products?sort=-created_at
# 複数フィールド(カンマ区切り)
GET /api/v1/products?sort=-featured,price,-created_at全文検索
# 検索クエリ パラメーター
GET /api/v1/products?q=wireless+headphones
# フィールド固有の検索
GET /api/v1/users?email=aliceスパース フィールドセット
# 指定されたフィールドのみを返す(ペイロード削減)
GET /api/v1/users?fields=id,name,email
GET /api/v1/orders?fields=id,total,status&include=customer.name認証と認可
トークン ベース認証
# Authorization ヘッダー内のベアラー トークン
GET /api/v1/users
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
# API キー(サーバー間)
GET /api/v1/data
X-API-Key: sk_live_abc123認可パターン
// リソース レベル: 所有権を確認
app.get("/api/v1/orders/:id", async (req, res) => {
const order = await Order.findById(req.params.id);
if (!order) return res.status(404).json({ error: { code: "not_found" } });
if (order.userId !== req.user.id) return res.status(403).json({ error: { code: "forbidden" } });
return res.json({ data: order });
});
// ロール ベース: 権限を確認
app.delete("/api/v1/users/:id", requireRole("admin"), async (req, res) => {
await User.delete(req.params.id);
return res.status(204).send();
});レート制限
ヘッダー
HTTP/1.1 200 OK
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640000000
# 超過した場合
HTTP/1.1 429 Too Many Requests
Retry-After: 60
{
"error": {
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded. Try again in 60 seconds."
}
}レート制限ティア
バージョン管理
URL パス バージョン管理(推奨)
/api/v1/users
/api/v2/users長所: 明示的、ルーティングが簡単、キャッシャブル 短所: バージョン間で URL が変更される
ヘッダー バージョン管理
GET /api/users
Accept: application/vnd.myapp.v2+json長所: クリーンな URL 短所: テストが困難、忘れやすい
バージョン管理戦略
More skills from affaan-m/ECC
- AaccessibilityWCAG 2.2 レベル AA 標準を用いてインクルーシブなデジタルプロダクトを設計・実装・監査します。Web 用のセマンティック ARIA および Web・ネイティブプラットフォーム(iOS/Android)のアクセシビリティトレイトを生成するために使用します。
- Aagent-architecture-auditエージェントおよび LLM アプリケーション向けのフルスタック診断。12 層のエージェントスタックにおけるラッパーリグレッション、メモリ汚染、ツール規律の失敗、隠れた修復ループ、レンダリング破損を監査します。重要度順の発見事項とコードファーストの修正を生成します。エージェントアプリケーション、自律ループ、または LLM を活用した機能を構築する開発者に必須です。
- Aagent-evalカスタムタスクでコーディングエージェント(Claude Code、Aider、Codex など)をヘッドツーヘッドで比較し、合格率、コスト、時間、一貫性のメトリクスを測定します
- Aagent-harness-constructionAI エージェントのアクション空間、ツール定義、観測フォーマットを設計・最適化して完了率を向上させます。
- Aagent-introspection-debuggingStructured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.
- Aagent-introspection-debuggingキャプチャ、診断、封じ込め回復、内省レポートを使用した AI エージェント障害のための構造化された自己デバッグワークフロー。
- Aagent-payment-x402タスクごとのバジェット、支出コントロール、ノンカストディアルウォレットを備えた x402 決済実行を AI エージェントに追加します。agentwallet-sdk を通じて Base をサポートし、OKX Payments / OKX エージェント決済プロトコルを通じて X Layer をサポートします。
- Aagent-sortBuild an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.
- Aagent-sort並行リポジトリ対応のレビューパスを使用して、スキル、コマンド、ルール、フック、エクストラを DAILY と LIBRARY のバケットに分類することで、特定のリポジトリ向けのエビデンスに基づいた ECC インストール計画を構築します。プロジェクトが完全なバンドルをロードする代わりに実際に必要なものに ECC をトリミングする必要がある場合に使用します。
- Aagentic-engineeringOperate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when AI agents perform most implementation work and humans enforce quality and risk controls.
- Aagentic-engineering評価ファースト実行、分解、コスト対応モデルルーティングを使用してエージェニックエンジニアとして動作します。
- Aagentic-osClaude Code 上に永続的なマルチエージェントオペレーティングシステムを構築します。カーネルアーキテクチャ、スペシャリストエージェント、スラッシュコマンド、ファイルベースのメモリ、スケジュールされた自動化、外部データベースなしの状態管理をカバーします。