api-and-interface-design

Designs stable REST APIs, TypeScript contracts, and idempotent endpoints with consistent error semantics.

1|Updated Sep 4, 2026
One-click install
npx skills add https://github.com/SanHsien/agent-skills --skill api-and-interface-design-sanhsien
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-and-interface-design
Source: https://github.com/SanHsien/agent-skills/tree/main/skills/api-and-interface-design
Command: npx skills add https://github.com/SanHsien/agent-skills --skill api-and-interface-design-sanhsien

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Public interfaces become de facto contracts the moment consumers depend on them, and inconsistent error handling, breaking changes, or unsafe retries silently erode API stability. This Skill guides the design of APIs and module boundaries that are hard to misuse and safe to evolve. ## Core Features & Use Cases - Contract-First Design: Define typed input/output schemas, discriminated unions, and branded ID types before implementation. - Consistent Error Semantics: Enforce a single structured error format with correct HTTP status code mapping across all endpoints. - Idempotency Implementation: Honour Idempotency-Key headers with atomic claims via unique constraints, payload guards, and deliberate in-flight duplicate handling. - Use Case: When adding a payments endpoint, use this Skill to design the endpoint contract, derive a stable idempotency key from the order ID, and ensure concurrent retries cannot double-charge a customer. ## Quick Start Ask the agent to design a REST API for a new resource following the api-and-interface-design skill, including typed contracts, pagination, and idempotent writes.

Frequently Asked Questions about api-and-interface-design

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

FAQPage Schema
How do I design a REST API that won't break existing consumers?

Define the contract first with typed input and output schemas, then evolve it by adding optional fields only. Never change existing field types or remove fields, and follow consistent naming conventions like plural nouns for endpoints and camelCase for fields.

How to implement idempotency keys for payment or POST endpoints?

Accept an Idempotency-Key header derived from an immutable identifier like an order ID, then claim it atomically with a database unique constraint before executing the side effect. Reject the same key reused with a different payload, and set key retention longer than any retry path including dead-letter replays.

Where should input validation happen in an API?

Validate only at system boundaries: API route handlers, form submissions, environment variable loading, and third-party API responses. Internal functions that share type contracts should trust already-validated data rather than re-validating.

Should I use PUT or PATCH for updating resources?

Use PATCH for partial updates where only provided fields change, which matches what clients actually send. PUT requires the full object on every request and is rarely what consumers want for typical update operations.

What is Hyrum's Law and why does it matter for API design?

Hyrum's Law states that all observable behaviors of an API will be depended on by someone, regardless of the documented contract. It means every public behavior is a commitment, so avoid leaking implementation details and plan deprecation at design time.