Api Designのロゴ

Api Design

コミュニティ
kazdenc
api-design

RESTful API design conventions covering URL structure, HTTP methods, error formats, pagination, versioning, and authentication patterns. Use when designing, reviewing, or implementing APIs. Triggers on API design, endpoint structure, REST conventions, or backend architecture tasks.

概要

公開者kazdenc
リポジトリbuilder-skills
スキル名api-design
スター
46
フォーク
5
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    kazdencがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルApi DesignをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/kazdenc/builder-skills/tree/main/.claude/skills/dev/frameworks/api-design
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/kazdenc/builder-skills.git /tmp/builder-skills
mkdir -p .claude/skills
cp -r /tmp/builder-skills/.claude/skills/dev/frameworks/api-design .claude/skills/api-design
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでApi Designを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にApi Designを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Api Designは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

API Design

Apply these conventions when designing, reviewing, or implementing RESTful APIs. Consistency matters more than cleverness — follow the patterns below.

URL Structure

Use nouns for resources, not verbs. Resources are things, not actions.

RuleCorrectIncorrect
Plural nouns/users, /orders/user, /getOrders
Nouns, not verbsPOST /usersPOST /createUser
Kebab-case for multi-word/line-items/lineItems, /line_items
Nest for relationships (max 2 levels)/users/:id/orders/users/:id/orders/:orderId/items/:itemId
Flat when parent is obvious/orders/:orderId/items/users/:userId/orders/:orderId/items

Query Parameters

Use query parameters for filtering, sorting, searching, and pagination. Never encode these in the URL path.

GET /users?status=active&sort=-created_at&limit=20&cursor=abc123
GET /orders?user_id=42&min_total=100&fields=id,status,total
ParameterConventionExample
FilterField name as key?status=active&role=admin
SortField name, prefix - for descending?sort=-created_at,name
Searchq parameter?q=john
Field selectionfields comma-separated?fields=id,name,email
Paginationcursor or offset/limit?cursor=abc&limit=20

HTTP Methods

MethodPurposeIdempotentRequest BodySuccess CodeResponse Body
GETRetrieve resource(s)YesNo200Resource or collection
POSTCreate a new resourceNoYes201Created resource
PUTReplace a resource entirelyYesYes200Updated resource
PATCHPartially update a resourceNo*Yes200Updated resource
DELETERemove a resourceYesNo204No body

*PATCH is not inherently idempotent but can be implemented as such. Treat it as non-idempotent by default.

Key rules:

  • GET must never mutate state. Ever.
  • PUT replaces the entire resource — omitted fields are removed or reset to defaults.
  • PATCH updates only the fields included in the body.
  • POST to a collection creates a new resource. Return the created resource with its id.
  • DELETE should succeed silently if the resource is already gone (idempotent).

Status Codes

Use the most specific appropriate code. Don't return 200 for everything.

2xx — Success

CodeMeaningUse When
200 OKRequest succeededGET, PUT, PATCH success
201 CreatedResource createdPOST success — include Location header
204 No ContentSuccess, no bodyDELETE success, or PUT/PATCH when no body is needed

4xx — Client Error

CodeMeaningUse When
400 Bad RequestMalformed requestInvalid JSON, missing required fields, validation failures
401 UnauthorizedNot authenticatedMissing or invalid authentication token
403 ForbiddenAuthenticated but not allowedUser lacks permission for this action
404 Not FoundResource doesn't existID not found, or route doesn't exist
405 Method Not AllowedWrong HTTP methodPOST to a read-only resource
409 ConflictState conflictDuplicate creation, version mismatch
422 Unprocessable EntitySemantic validation failureValid JSON, but business rules violated
429 Too Many RequestsRate limit exceededInclude Retry-After header

5xx — Server Error

CodeMeaningUse When
500 Internal Server ErrorUnexpected failureUnhandled exception — log it, don't leak details
502 Bad GatewayUpstream failureA dependency returned an invalid response
503 Service UnavailableTemporarily downMaintenance or overload — include Retry-After

Error Format

Return errors in a consistent shape. Every error response uses this structure:

json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request body failed validation.",
    "details": [
      { "field": "email", "message": "Must be a valid email address." },
      { "field": "age", "message": "Must be at least 18." }
    ]
  }
}
FieldTypeRequiredDescription
error.codestringYesMachine-readable error code (UPPER_SNAKE_CASE)
error.messagestringYesHuman-readable summary
error.detailsarray | objectNoField-level errors, additional context

Rules:

  • Always return the same top-level { error: { ... } } shape for all error responses.
  • Use code for programmatic handling (clients switch on it), message for display.
  • Never expose stack traces, internal paths, or database errors in production.
  • Include a request_id in error responses (or top-level meta) for debugging.

Pagination

Cursor-Based (Preferred)

Use cursor-based pagination by default. It handles inserts/deletes gracefully and scales to large datasets.

Request:

GET /users?limit=20&cursor=eyJpZCI6MTAwfQ

Response:

json
{
  "data": [ { "id": 101, "name": "Ada" }, { "id": 102, "name": "Bob" } ],
  "pagination": {
    "next_cursor": "eyJpZCI6MTAyfQ",
    "has_more": true
  }
}
FieldDescription
next_cursorOpaque string — encode whatever your DB needs (usually last ID)
has_moreBoolean — tells client whether to fetch again

Offset-Based (When Needed)

Use offset pagination only when users need to jump to arbitrary pages (admin tables, search results).

Request:

GET /users?offset=40&limit=20

Response:

json
{
  "data": [ { "id": 41, "name": "Ada" } ],
  "pagination": {
    "offset": 40,
    "limit": 20,
    "total": 523
  }
}

Warning: Offset pagination degrades on large datasets (DB must skip offset rows). Never use for infinite scroll.

Authentication

Bearer Tokens (Preferred for User Auth)

Pass tokens in the Authorization header:

Authorization: Bearer eyJhbGciOiJSUzI1NiIs...
  • Use short-lived access tokens (15 min–1 hr) with refresh tokens.
  • Validate tokens on every request. Don't cache validation results.
  • Return 401 for missing/expired tokens, 403 for insufficient permissions.

API Keys (For Server-to-Server)

Pass API keys in a custom header or as a query parameter (header preferred):

X-API-Key: sk_live_abc123def456
AspectRecommendation
Where to sendX-API-Key header (preferred) or Authorization: ApiKey <key>
Key formatPrefix with environment: sk_live_, sk_test_
StorageHash keys server-side, never store plaintext
RotationSupport multiple active keys for zero-downtime rotation

When to Use Each

ScenarioAuth Method
Browser/mobile app user sessionsBearer token (OAuth 2.0 / JWT)
Server-to-server integrationAPI key
Third-party developer accessOAuth 2.0 with scopes
Internal microservicesmTLS or signed JWTs

Versioning

URL Versioning (Preferred)

Prefix major versions in the URL path:

GET /v1/users
GET /v2/users
  • Version only when you introduce breaking changes.
  • Run old versions in parallel during migration. Set a sunset date and communicate it.
  • Non-breaking additions (new optional fields, new endpoints) do not require a version bump.

Header Versioning (Alternative)

Accept: application/vnd.myapi.v2+json

Use header versioning when URL versioning creates routing complexity or you need fine-grained version control. URL versioning is simpler for most cases.

What Counts as a Breaking Change

BreakingNot Breaking
Removing a field from a responseAdding a new optional field to a response
Renaming a fieldAdding a new endpoint
Changing a field's typeAdding a new optional query parameter
Removing an endpointAdding a new enum value (if clients handle unknown)
Making an optional field requiredImproving error messages

Rate Limiting

Include rate-limit headers in every response so clients can self-regulate:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 742
X-RateLimit-Reset: 1702483200
HeaderDescription
X-RateLimit-LimitMax requests allowed in the window
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetUnix timestamp when the window resets

When the limit is exceeded, return:

json
{
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Too many requests. Retry after 30 seconds.",
    "details": {
      "retry_after": 30
    }
  }
}

Return 429 Too Many Requests with a Retry-After header (in seconds).

Anti-Patterns

Avoid these. When you see them in a codebase, flag or refactor.

Anti-PatternProblemDo Instead
Verbs in URLs/getUsers, /deleteOrderUse HTTP methods: GET /users, DELETE /orders/:id
Deep nesting (3+ levels)/users/:id/orders/:oid/items/:iid/reviewsFlatten: /order-items/:iid/reviews
200 for errorsClient can't distinguish success from failure by statusUse appropriate 4xx/5xx codes
GET for mutationsBreaks caching, prefetching, crawlersUse POST, PUT, PATCH, DELETE
Plural/singular inconsistency/user/1 but /ordersAlways use plural: /users/1, /orders
Returning arrays at rootVulnerable to JSON hijacking, can't add metadataWrap in { "data": [...] }
Leaking internal errorsStack traces, SQL errors in responsesReturn generic message, log details server-side
Ignoring Accept headersClient can't negotiate content typeRespect Accept or return 406
Custom status codesClients won't understand themStick to standard HTTP status codes
Inconsistent error shapesSome errors return { message }, others { error }Use one error shape everywhere

よくある質問

AIスキル「Api Design」では何ができますか?

RESTful API design conventions covering URL structure, HTTP methods, error formats, pagination, versioning, and authentication patterns. Use when designing, reviewing, or implementing APIs. Triggers on API design, endpoint structure, REST conventions, or backend architecture tasks.

TypingMindでApi Designを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Api Designはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにApi Designをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/kazdenc/builder-skills/tree/main/.claude/skills/dev/frameworks/api-designを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Api Designを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Api Designは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもApi Designを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Api Design」は無料ですか?

はい。kazdencがGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇