Api design

From qa-aman/claude-skills · View interactive version

Api design is an AI agent skill from the GitHub repository qa-aman/claude-skills. Design clean and consistent APIs. Use when the user says "design an API", "API design review", "design these endpoints", "REST API for X", "GraphQL schema", "API contract", "how should this endpoint work", "review my API design", or wants to create or improve an API interface - even if they don't ex

How to use this skill

Skill file

Overview

Based on "A Philosophy of Software Design" by John Ousterhout. Ousterhout's key principle: modules should be deep - simple interface, powerful implementation. Applied to APIs: the surface area exposed to callers should be as small as possible, while the behavior provided should be as rich as possible. A leaky abstraction (where callers need to understand implementation details) is a design failure.

Workflow

Step 1: Define the API's job

Before designing any endpoint, state what the API enables:

Ousterhout: if callers need to know how the API works internally to use it correctly, the API is leaky.

Step 2: Design resources (REST) or schema (GraphQL)

REST:

GraphQL:

Step 3: Design request and response contracts

For each endpoint:

Endpoint: [METHOD] /path/{param}
Purpose: [one sentence]
Auth: [required scope or token type]

Request:
  Path params: [required identifiers]
  Query params: [optional filters, pagination]
  Body: [JSON schema with required/optional fields]

Response (200):
  [JSON schema]

Errors:
  400 - [validation failure - which fields, why]
  401 - [unauthenticated]
  403 - [unauthorized - caller lacks permission]
  404 - [resource not found]
  409 - [conflict - e.g. duplicate]
  422 - [unprocessable entity - valid syntax, invalid semantics]
  500 - [internal error]

Step 4: Apply consistency rules

Pick conventions and apply them everywhere:

Inconsistency is the top complaint from API consumers.

Step 5: Design for the caller's mental model

Ousterhout's information hiding principle: don't expose implementation artifacts.

Step 6: Version the API

Every public API needs a versioning strategy before it ships:

Anti-Patterns

1. Verbs in resource paths

Bad: POST /createUser, GET /getUserById

Good: POST /users, GET /users/{id}

2. Inconsistent error shapes

Bad: Some endpoints return { error: "message" }, others return { message: "error" }.

Good: One error schema, applied everywhere.

3. Leaking implementation details

Bad: /api/db/users_table/row/42

Good: /api/users/42

4. No versioning plan on day 1

Bad: Ship v1 with no versioning, then break callers when you need to change the contract.

Good: Version from the first public release. Breaking changes require a new version.

Quality Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.