api-design
Guidelines for designing RESTful APIs and TypeScript interfaces. Use when designing new endpoints, reviewing API contracts, or structuring data models.
Install
mkdir -p .claude/skills/api-design && curl -L -o skill.zip "https://mcp.directory/api/skills/download/4035" && unzip -o skill.zip -d .claude/skills/api-design && rm skill.zipInstalls to .claude/skills/api-design
About this skill
API Design Guidelines
Overview
This skill provides guidelines for designing clean, consistent APIs. Apply these patterns when creating new endpoints, defining TypeScript interfaces, or reviewing API contracts.
Keywords: API design, REST, endpoints, TypeScript interfaces, data modeling, HTTP methods, response formats
REST Endpoint Design
URL Structure
/{resource} # Collection
/{resource}/{id} # Single resource
/{resource}/{id}/{sub-resource} # Nested resource
Good examples:
GET /users- List usersGET /users/123- Get user 123POST /users/123/orders- Create order for user 123
Avoid:
/getUsers- Don't use verbs in URLs/user/list- Don't use action words/users/123/getOrders- HTTP method implies action
HTTP Methods
| Method | Purpose | Idempotent | Body |
|---|---|---|---|
| GET | Read resource | Yes | No |
| POST | Create resource | No | Yes |
| PUT | Replace resource | Yes | Yes |
| PATCH | Update resource | No | Yes |
| DELETE | Remove resource | Yes | No |
Response Codes
Success:
200- OK (GET, PUT, PATCH with body)201- Created (POST)204- No Content (DELETE, PUT/PATCH without body)
Client errors:
400- Bad Request (validation failed)401- Unauthorized (no/invalid auth)403- Forbidden (no permission)404- Not Found409- Conflict (duplicate, state conflict)422- Unprocessable Entity (semantic errors)
Server errors:
500- Internal Server Error503- Service Unavailable
Response Formats
Success Response
// Single resource
{
"data": {
"id": "123",
"name": "Example",
"createdAt": "2024-01-15T10:30:00Z"
}
}
// Collection
{
"data": [...],
"meta": {
"total": 100,
"page": 1,
"pageSize": 20
}
}
Error Response
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
}
}
TypeScript Interface Design
Naming Conventions
// Entities use PascalCase nouns
interface User {}
interface OrderItem {}
// Request/Response types include suffix
interface CreateUserRequest {}
interface GetUserResponse {}
// Params types for function arguments
interface ListUsersParams {}
Required vs Optional
// Required fields: always present
interface User {
id: string;
email: string;
createdAt: Date;
}
// Optional fields: may be undefined
interface CreateUserRequest {
email: string;
name?: string; // Optional
metadata?: Record<string, unknown>;
}
Discriminated Unions
Use for type-safe variants:
type PaymentMethod =
| { type: 'card'; cardNumber: string; expiry: string }
| { type: 'bank'; accountNumber: string; routingNumber: string }
| { type: 'crypto'; walletAddress: string };
// Usage
function processPayment(method: PaymentMethod) {
switch (method.type) {
case 'card':
// TypeScript knows cardNumber exists
return chargeCard(method.cardNumber);
case 'bank':
return initiateTransfer(method.accountNumber);
case 'crypto':
return sendCrypto(method.walletAddress);
}
}
Pagination
Offset-based (Simple)
interface PaginationParams {
page?: number; // Default: 1
pageSize?: number; // Default: 20, max: 100
}
interface PaginatedResponse<T> {
data: T[];
meta: {
page: number;
pageSize: number;
total: number;
totalPages: number;
};
}
Cursor-based (Scalable)
interface CursorParams {
cursor?: string;
limit?: number;
}
interface CursorResponse<T> {
data: T[];
meta: {
nextCursor: string | null;
hasMore: boolean;
};
}
Versioning
URL Versioning (Recommended)
/api/v1/users
/api/v2/users
Header Versioning
Accept: application/vnd.api+json; version=2
Common Patterns
Filtering
GET /users?status=active&role=admin
GET /orders?createdAfter=2024-01-01&createdBefore=2024-02-01
Sorting
GET /users?sort=createdAt:desc
GET /users?sort=lastName:asc,firstName:asc
Field Selection
GET /users?fields=id,name,email
GET /users/123?include=orders,profile
Security Considerations
- Authentication - Use Bearer tokens in Authorization header
- Rate limiting - Include
X-RateLimit-*headers - Input validation - Validate all request bodies with schemas
- Output encoding - Escape HTML in responses if rendered
- CORS - Configure allowed origins explicitly
More by mastra-ai
View all →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
rust-coding-skill
UtakataKyosui
Guides Claude in writing idiomatic, efficient, well-structured Rust code using proper data modeling, traits, impl organization, macros, and build-speed best practices.
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.