api-and-interface-design

Guides design of stable REST APIs, TypeScript interfaces, and module contracts.

1|Updated May 25, 2020
One-click install
npx skills add https://github.com/titaneric/dotfiles --skill api-and-interface-design-titaneric
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-and-interface-design
Source: https://github.com/titaneric/dotfiles/tree/main/dot_agents/skills/api-and-interface-design
Command: npx skills add https://github.com/titaneric/dotfiles --skill api-and-interface-design-titaneric

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Poorly designed APIs and interfaces create breaking changes, inconsistent error handling, and tight coupling between modules. This Skill provides concrete principles and patterns for designing stable contracts that are hard to misuse and safe to evolve. ## Core Features & Use Cases - Contract-First Design: Define typed interfaces before implementation, with input/output separation and branded ID types in TypeScript. - REST API Patterns: Standard conventions for resource naming, pagination, filtering, and partial updates via PATCH. - Consistent Error Semantics: A single structured error format mapped to HTTP status codes, with validation enforced only at system boundaries. - Use Case: When creating a new /api/tasks endpoint, apply the Skill to define typed request/response schemas, paginated list responses, and a uniform error body before writing any handler code. ## Quick Start Ask the AI to design a REST API for a new resource following the api-and-interface-design principles, including typed contracts, pagination, and consistent error responses.

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 clients?

Prefer addition over modification: add new optional fields instead of changing or removing existing ones. Use PATCH for partial updates, version only when unavoidable, and treat every observable behavior as a commitment under Hyrum's Law.

What is the best way to structure API error responses?

Use one consistent error shape everywhere: a machine-readable code, a human-readable message, and optional details. Map errors to standard HTTP status codes like 400, 401, 403, 404, 409, 422, and 500, and never mix patterns across endpoints.

Where should input validation happen in an API?

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

Should I validate third-party API responses before using them?

Yes. Third-party responses are untrusted data and must be validated for shape and content before use in logic or rendering. A compromised external service can return unexpected types or malicious content.

When should I use discriminated unions in TypeScript interfaces?

Use discriminated unions when a value has distinct variants with different fields, such as task statuses. A shared discriminator field like 'type' gives consumers automatic type narrowing in switch statements.

What are common REST API design mistakes to avoid?

Avoid verbs in URLs, inconsistent error formats, list endpoints without pagination, breaking changes to existing fields, and scattered validation. These create unpredictable contracts that consumers cannot rely on.