api-and-interface-design

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

Updated Mar 12, 2026
One-click install
npx skills add https://github.com/RavitejaKarra24/dotfiles --skill api-and-interface-design-ravitejakarra24
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-and-interface-design
Source: https://github.com/RavitejaKarra24/dotfiles/tree/main/agents/.agents/skills/api-and-interface-design
Command: npx skills add https://github.com/RavitejaKarra24/dotfiles --skill api-and-interface-design-ravitejakarra24

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, hard-to-misuse interfaces before implementation begins. ## Core Features & Use Cases - Contract-First Design: Define typed interfaces, input/output schemas, and error semantics before writing implementation code. - REST API Patterns: Covers resource naming, pagination, filtering, partial updates with PATCH, and consistent HTTP status code mapping. - TypeScript Interface Patterns: Discriminated unions for variants, input/output type separation, and branded types for IDs. - Use Case: When creating a new REST endpoint for a task management feature, use this Skill to define the TaskAPI contract, standardize error responses, add pagination to list endpoints, and ensure new fields are additive and backward compatible. ## Quick Start Ask the AI to design a versioned REST API contract with typed inputs, outputs, and consistent error handling for your new resource endpoints.

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?

Prefer addition over modification: add new fields as optional and never change or remove existing field types. Define the contract first with typed inputs and outputs, and plan for deprecation at design time since Hyrum's Law means users depend on every observable behavior.

What is the best way to handle API error responses consistently?

Pick one error strategy and use it everywhere: map HTTP status codes (400, 401, 403, 404, 409, 422, 500) to a structured error body with a machine-readable code, human-readable message, and optional details. Never mix patterns like throwing, returning null, and returning error objects across endpoints.

Where should input validation happen in an API?

Validate at system boundaries where external input enters: API route handlers, form submissions, third-party API responses, and environment variables. Do not validate between internal functions that share type contracts or on data from your own database.

Should I use PUT or PATCH for updating resources?

Use PATCH for partial updates where only provided fields change, which is what clients actually want. PUT requires sending the full object every time, making it fragile for consumers and prone to overwriting unrelated fields.

When should I use discriminated unions in TypeScript interfaces?

Use discriminated unions when a type has multiple variants with different associated data, such as task statuses like pending, in_progress, or completed. A shared discriminator field enables type narrowing in switch statements so consumers handle each variant explicitly.

Why should third-party API responses be validated before use?

Third-party responses are untrusted data that can contain unexpected types, malicious content, or instruction-like text from compromised or misbehaving services. Validate their shape and content before using them in logic, rendering, or decision-making.