api-design-principles

Design REST and GraphQL APIs using resource-oriented patterns, pagination, and versioning standards.

Updated May 28, 2026
One-click install
npx skills add https://github.com/changfengpro/agent-skills --skill api-design-principles-changfengpro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-design-principles
Source: https://github.com/changfengpro/agent-skills/tree/main/skills/api-design-principles
Command: npx skills add https://github.com/changfengpro/agent-skills --skill api-design-principles-changfengpro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve? Teams building APIs often ship inconsistent endpoints, incorrect HTTP semantics, missing pagination, and GraphQL schemas that suffer from N+1 query problems, leading to breaking changes and frustrated API consumers. ## Core Features & Use Cases - REST Design Guidance: Resource-oriented URL structures, correct HTTP method semantics, status code selection, pagination, filtering, rate limiting, and versioning strategies. - GraphQL Schema Patterns: Schema-first design with Relay cursor pagination, input/payload mutation patterns, DataLoader-based N+1 prevention, and deprecation workflows. - Ready-to-Use Assets: A FastAPI template with pagination and error handling, plus a comprehensive pre-implementation review checklist covering security, monitoring, and documentation. - Use Case: When reviewing a new API specification before implementation, use the checklist to verify status codes, pagination, authentication, and error formats are correctly defined. ## Quick Start Ask the assistant to review your API endpoint design or generate a paginated FastAPI endpoint following REST best practices.

Frequently Asked Questions about api-design-principles

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

FAQPage Schema
How do I design a REST API with proper pagination?

Use offset-based pagination with page and page_size query parameters for simple cases, or cursor-based pagination for large datasets. Always include pagination metadata like total count and page numbers, enforce a maximum page size, and apply pagination to every collection endpoint.

REST vs GraphQL: which should I choose for my API?

REST fits resource-oriented services with predictable access patterns and simple caching needs. GraphQL suits clients needing flexible data fetching, such as mobile apps avoiding over-fetching, but requires DataLoaders and query complexity limits to stay performant.

How do I prevent N+1 queries in GraphQL resolvers?

Use the DataLoader pattern to batch and cache relationship lookups within a single request. A DataLoader collects all IDs requested during field resolution and fetches them in one database query, returning results mapped to the original order.

What HTTP status codes should a REST API return?

Return 200 for successful reads and updates, 201 for resource creation, 204 for deletions, 400 for malformed requests, 401 for missing authentication, 403 for insufficient permissions, 404 for missing resources, 422 for validation errors, and 429 for rate limiting.

How do I version an API without breaking existing clients?

Use URL versioning like /api/v1/users for clarity, or header versioning for cleaner URLs. In GraphQL, avoid versioning entirely by deprecating fields with the @deprecated directive and adding new fields, since schemas evolve additively.

When should I avoid deep URL nesting in REST APIs?

Avoid nesting deeper than two levels, such as /users/{id}/orders/{orderId}/items. Deeply nested URLs become brittle and hard to maintain; instead, expose nested resources as top-level endpoints filtered by query parameters.