agentsclimarketplace

Api design

Skill ahgraber/skills/skills/api-design

Agent skills

Install
npx -y skills add ahgraber/skills --skill api-design

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 5 stars5 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when designing, reviewing, or planning REST or GraphQL APIs — endpoint structure, schema design, versioning, error handling, pagination, URI naming, or choosing between REST and GraphQL. Also triggers for OpenAPI spec creation and API contract review.

SKILL.md

8.0 KB, as published. Nobody here has run it

API Design

When to Use

  • Designing new API endpoints or schemas
  • Reviewing existing API contracts for consistency
  • Choosing between REST and GraphQL for a project
  • Planning versioning, pagination, or error handling strategies
  • Creating or reviewing OpenAPI/GraphQL specifications
  • Naming URIs, fields, or resources
  • Reviewing API security posture

When NOT to use:

  • Framework-specific implementation details (though FastAPI patterns are available as a secondary reference below)
  • Database schema design (unless it directly affects the API contract)
  • Frontend data fetching code (unless reviewing the API contract it consumes)

Invocation Notice

When invoked by name, announce: "Using api-design to guide API design decisions."

Universal Principles

These apply regardless of REST or GraphQL:

  1. Prefer design-first for public, cross-team, or governance-heavy APIs. Write the contract (OpenAPI spec or GraphQL schema) before implementation. Code-first is the normal workflow for frameworks like FastAPI that generate the contract from code, and is acceptable for rapid prototypes or internal tools with stable requirements. The choice is driven by governance needs, not protocol correctness.
  2. Consistency is non-negotiable. Pick conventions and apply them uniformly across every endpoint, field, and error response.
  3. API surface is not database surface. Never mirror internal data models in public contracts. Abstract so you can change internals without breaking clients. See rest-design.md § API Surface Is Not Database Surface for rationale, anti-patterns, and decoupling strategies.
  4. Validate and shape at the boundary. Enforce input constraints and response shaping at the API boundary. Authenticate before business logic runs. As a strong default, keep fine-grained authorization policy in the domain/business layer — but coarse access control (e.g., "only authenticated users") is legitimately enforced in gateways or middleware before the domain layer.
  5. Evolve without breaking. Hyrum's Law: with enough users, every observable behavior of your API — including undocumented quirks, error message text, and field ordering — becomes a de facto contract someone depends on. Design with that in mind: be intentional about what you expose, and treat any change as potentially breaking until proven otherwise. Additive changes are usually safe, but verify compatibility against clients — adding a GraphQL enum value is schema-safe yet can surprise clients that assume exhaustive handling. Removal, renaming, and type changes require versioning (REST) or deprecation workflows (GraphQL).
  6. Security is structural. HTTPS, authentication, authorization, rate limiting, and input validation are not optional additions — they are part of the design.

Use the references below as scoped guidance. Some references describe broad consensus, while others document strong defaults or ecosystem-specific patterns.

Route by Task

Design TaskReferenceWhen to Load
REST vs GraphQL decisionrest-vs-graphql.mdStarting a new API or evaluating a paradigm shift
REST endpoint designrest-design.mdDesigning REST resources, methods, status codes
GraphQL schema/query/mutation designgraphql-design.mdDesigning GraphQL types, queries, mutations, subscriptions
URI/URL naminguri-design.mdNaming endpoints, path segments, query parameters
API versioningversioning.mdPlanning version strategy, deprecation, migration
Error responseserror-handling.mdDesigning error formats, status code usage, RFC 9457
Pagination and filteringpagination-filtering.mdLists, collections, search results, sorting
FastAPI implementationfastapi-practices.mdBuilding APIs with FastAPI specifically

How to use this table: Load only the references relevant to the current task. For a new API design, start with rest-vs-graphql.md, then load the paradigm-specific reference. For targeted questions (e.g., "how should we version this?"), load only that reference.

Quick Decision: REST vs GraphQL

  • REST: simpler caching, lower learning curve, native file uploads, smaller security surface.
  • GraphQL: client-specified queries, nested data without over-fetching, built-in subscriptions — but requires depth/cost limiting, custom caching, and more schema governance.
  • Hybrid: can work, but increases operational and governance complexity.
  • Caution: GraphQL was not designed for file uploads; use multipart workarounds or a separate REST endpoint. REST requires careful endpoint design to avoid N+1 orchestration.

For the full decision tree and tradeoff matrix, load rest-vs-graphql.md.

Common Mistakes

MistakeFix
Verbs in REST URIs (/getUsers, /createOrder)Use nouns + HTTP methods for CRUD; verbs only for controller resources (POST /orders/{id}/cancel)
Exposing database IDs/structure in APIAbstract with slugs, UUIDs, and domain-oriented shapes; use a mapping layer, not auto-serialization
Inconsistent error formats across endpointsDefine one error schema, use it everywhere
No pagination on collection endpointsPaginate unbounded or growth-prone collections; small bounded reference data may not need it — always set default and max page sizes when pagination is used
Breaking changes without versioningUse additive changes; version when breaking is unavoidable
Generic GraphQL mutations (updateEntity)Use specific semantic mutations (publishPost, archiveOrder)
Auth logic in resolvers/handlers instead of business layerDelegate authorization to domain services
Nullable everything / non-null everythingBe intentional: non-null only when you can guarantee presence

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.