api-patterns
API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.
Author
Category
Development ToolsInstall
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
API Patterns - API Design Decision Assistant
API Patterns is an API design principles and decision-guidance skill that helps developers choose the appropriate API style (REST, GraphQL, tRPC) based on real-world scenarios, and guides response format design, versioning strategies, pagination implementation, and other key architectural decisions.
Applicable Scenarios
Core Features
Frequently Asked Questions
How to choose between REST, GraphQL, and tRPC?
The choice depends on project context: REST is the most general and standardized option, suitable for public APIs and simple CRUD operations; GraphQL is suitable when clients need flexible queries, fewer network requests, and the data relationships are complex; tRPC is best for TypeScript full-stack projects, offering end-to-end type safety and a zero-configuration developer experience. The key questions to ask are: Who are the API consumers? What is the team’s tech stack? How complex are the data queries?
What are best practices for API versioning?
Common approaches include URI versioning (/v1/users), HTTP Header versioning (Accept: application/vnd.api.v1+json), and Query parameter versioning (?version=1). URI versioning is the most straightforward and suits public APIs; Header versioning keeps URLs cleaner but requires client cooperation; Query parameter versioning is the simplest but not recommended for complex scenarios. Regardless of the approach, plan deprecation policies and migration paths in advance.
How to design a consistent API error response format?
It is recommended to use an envelope pattern that wraps responses in a consistent structure: { data: {...}, errors: [...], meta: {...} }. Error details should include machine-readable error codes and human-readable messages, for example { "code": "VALIDATION_ERROR", "message": "Invalid email format", "field": "email" }. Avoid exposing internal stacks or database errors directly, and use appropriate HTTP status codes (4xx for client errors, 5xx for server errors).