api-design

Designs stable REST API contracts with RFC 9457 errors, idempotency, and versioning guidance.

Updated May 18, 2024
One-click install
npx skills add https://github.com/joshhornby/dotfiles --skill api-design-joshhornby
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-design
Source: https://github.com/joshhornby/dotfiles/tree/main/.claude/skills/api-design
Command: npx skills add https://github.com/joshhornby/dotfiles --skill api-design-joshhornby

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Public and cross-team APIs break consumers when error formats are inconsistent, retries duplicate side effects, or changes are not backward compatible. This Skill provides contract-first design patterns so externally consumed APIs stay stable, secure, and evolvable. ## Core Features & Use Cases - Contract-first REST design: Typed input/output schemas, resource naming conventions, pagination, filtering, and additive-only evolution guided by Hyrum's Law. - Consistent error semantics: RFC 9457 Problem Details for public APIs or a simpler documented shape for internal ones, with correct HTTP status mapping and no leaked internals. - Idempotency and resilience: Idempotency-key handling for POST, safe DELETE semantics, rate-limit headers, and HTTP caching rules. - Deep-dive resources: On-demand references covering API evolution and deprecation (Sunset/Deprecation headers), OWASP API Security Top 10, JWT best practices (RFC 8725), and HTTP fundamentals (RFC 9205). - Use Case: When designing a new payments endpoint, use this Skill to define the typed contract first, return RFC 9457 validation errors with a 422 status, and require an Idempotency-Key header so client retries never create duplicate charges. ## Quick Start Ask the AI to design a versioned REST endpoint for creating payments with RFC 9457 error responses and idempotency-key handling.

Frequently Asked Questions about api-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a REST API that stays backward compatible?

Define the contract first with typed input and output schemas, then evolve it additively: only add optional fields, new enum values, and new endpoints. Never remove fields, change types, or make optional fields required, since consumers depend on every observable behavior.

What error format should a public API use?

Public APIs should use RFC 9457 Problem Details with the application/problem+json content type, including type, title, status, and detail members. Internal APIs with a single frontend can use a simpler consistent shape with a machine-readable error code and correct HTTP status.

How do I make POST requests idempotent?

Require a client-provided Idempotency-Key header, claim it atomically scoped to the authenticated user, and store the response for replay. Return 409 if the same key arrives with different parameters, and keep a durable operation identity so retries never duplicate charges or records.

Should I use 400 or 422 for validation errors?

Return 400 when the request representation itself cannot be parsed, such as malformed JSON. Return 422 when parsing succeeds but the value fails the endpoint schema or business validation, and document whichever mapping you choose consistently.

When should I version an API versus evolve it?

Prefer evolving without versioning by making only additive changes and following Postel's Law. When breaking changes are unavoidable, use date-based version pinning like Stripe for paying customers, or URL path versioning as a pragmatic default for public APIs.

What are the most common API security mistakes?

The top OWASP risks are broken object-level authorization, where any authenticated user can access any object, and mass assignment from unvalidated request bodies. Scope lookups to the authenticated principal, validate input with closed schemas, and never trust third-party API responses without validation.