Skill

api-design

Design REST or GraphQL APIs: resource modeling, URL conventions, error contracts, versioning, pagination, idempotency keys, rate-limit headers. Use when creating a new API endpoint or reviewing API consistency.

Category
core
Version
0.1.0
License
MIT
Status
active
Length
88 lines
Source
skills/core/api-design/SKILL.md

Install and discovery

npx --yes --package @youcisla/agent-foundry agent-foundry-install

After the installer runs, this record is available as api-design. See the docs for harness roots and verification steps.

Contents

API Design

Design APIs that are predictable, versionable, and self-documenting.

Procedure

REST Conventions

  • Resources are nouns, plural: /users, /cases, /reflections
  • Actions are sub-resources: /users/{id}/sessions
  • Verbs only when nothing else fits: /users/{id}/verify-email

HTTP Methods

MethodActionIdempotent
GETexamineYes
POSTCreateNo (without key)
PUTReplaceYes
PATCHPartial updateNo
DELETEDeleteYes

Status Codes

CodeWhen
200Successful read/update
201Successful create (include Location)
204Successful delete / no body
400Malformed request
401Missing/invalid auth
403Not permitted
404Resource missing or hidden
409State collision
422Valid syntax, semantic fail
429Rate-limited (Retry-After)
500Unexpected server error

Error Contract

Every error uses the same shape:

{
  "error": {
    "code": "user_not_found",
    "message": "No user with id 'abc123'",
    "param": "user_id",
    "doc_url": "https://api.example.com/docs/errors#user_not_found"
  }
}
  • code: stable, snake_case, machine-readable
  • message: human-readable, may include the failing value
  • param: which field caused the issue
  • doc_url: always present for documented codes

Anti-patterns

  • An action encoded as a GET with side effects.
  • A new error shape for one endpoint.
  • A breaking response change without a version.
  • Pagination or idempotency left implicit.

References

  • details

Verification Checklist

  • [ ] Methods match side effects and idempotency.
  • [ ] Status codes follow the table.
  • [ ] Errors use the shared object shape.
  • [ ] Collection endpoints state pagination.
  • [ ] Breaking changes have a version path.