Api design

From open-gsd/gsd-pi · View interactive version

Api design is an AI agent skill from the GitHub repository open-gsd/gsd-pi. Design or review an HTTP/REST/GraphQL API for versioning, pagination, error shapes, idempotency, auth, status codes, cache headers, and breaking-change management. Use when asked to "design an API", "shape the endpoints", "design the schema", "add a new endpoint", "review this API", or when building

How to use this skill

Skill file

<objective>

Shape an HTTP or GraphQL API so callers get predictable, evolvable, and honest semantics. The deliverable is a concrete endpoint/schema sketch with: URL or operation names, method/verb, request shape, response shape, error shape, auth model, pagination strategy, and versioning stance. Optimize for "clients that exist in 2 years" over "client that's easy to write today".

</objective>

<context>

gsd-pi has design-an-interface for general module-interface design; this skill is the HTTP/GraphQL specialization. REST and GraphQL carry baggage — status codes, verbs, nullability, pagination — that a generic interface-design discussion glosses over.

Invocation points:

</context>

<core_principle>

CALLERS OUTLIVE YOUR ASSUMPTIONS. An API you ship today has to keep working when your internals change, when the mobile app version two is still in use, and when a third party integrates against it. Design for extension, not just for the current caller.

HONEST STATUS CODES. 200 OK with {"error": "not found"} is a lie. 404 says not found. Use the HTTP semantics the protocol offers — HTTP clients, caches, and intermediaries rely on them.

PAGINATION IS NON-OPTIONAL. Any list endpoint that doesn't paginate will eventually get a request for "all records" that kills your database.

</core_principle>

<process>

Step 1: Gather the contract

Answer, or ask (one round, 1–3 questions):

  1. Who are the callers? Internal service / mobile app / public third-party / same-repo frontend.
  2. What's the versioning stance? None / URL-path (/v1/) / header-based / GraphQL schema evolution.
  3. Auth model? Public / API key / OAuth / session cookie / mTLS / none-but-internal-only.
  4. Idempotency expectation? Is a retry safe? Required?
  5. Consistency model? Read-your-writes, eventual, serializable?

Step 2: Resource and operation naming

REST

GraphQL

Step 3: Methods and status codes

REST

| Method | Intent | Idempotent? | Default success |

|---|---|---|---|

| GET | Read | Yes | 200, or 304 if conditional |

| POST | Create or non-idempotent action | No | 201 with Location on create, 200 on action |

| PUT | Replace (full-object) | Yes | 200 with body, or 204 |

| PATCH | Partial update | No (usually) | 200 with body |

| DELETE | Remove | Yes | 204 |

Errors:

Never 200-with-error-body. Never 500 for a 4xx cause.

GraphQL

Step 4: Pagination

Step 5: Error shape

Standardize one shape and use it everywhere. Example REST:

{
  "error": {
    "code": "user_not_found",
    "message": "No user with id 42",
    "details": { "userId": 42 },
    "requestId": "req_abc123"
  }
}

Errors don't leak stack traces, file paths, or internal queries.

Step 6: Idempotency, caching, concurrency

Step 7: Versioning and evolution

Step 8: Review or write it up

If this is a review, produce findings in the same shape as security-review / review — file:line, category, recommendation.

If this is a new design, produce:

## <API name>

### Scope
<what the API is for, who calls it>

### Endpoints / Operations
- `POST /users` — create user. Request: `{email, name}`. Response 201: `{id, email, name, createdAt}` + `Location: /users/<id>`. Errors: 409 email taken, 422 invalid.
- ...

### Auth
<model + where to put the credential>

### Pagination
<cursor shape, max limit>

### Error shape
<one canonical shape>

### Idempotency / concurrency
<rules>

### Versioning
<stance + how breaking changes will be handled>

### OpenAPI / SDL
<link or inline>

Save architectural decisions with gsd_decision_save; it renders .gsd/DECISIONS.md.

</process>

<anti_patterns>

</anti_patterns>

<success_criteria>

</success_criteria>

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.