api-design-principles

Designs REST and GraphQL APIs with resource-oriented endpoints, pagination, versioning, and error handling patterns.

2|Updated Mar 7, 2025
One-click install
npx skills add https://github.com/AbdelrhmanUZaki/KnowledgeNuggets --skill api-design-principles-abdelrhmanuzaki
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: api-design-principles
Source: https://github.com/AbdelrhmanUZaki/KnowledgeNuggets/tree/main/2-setup/shared/gemini/config/skills/api-design-principles
Command: npx skills add https://github.com/AbdelrhmanUZaki/KnowledgeNuggets --skill api-design-principles-abdelrhmanuzaki

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing APIs without consistent standards leads to confusing endpoints, breaking changes, poor error handling, and frustrated developers. This Skill provides structured guidance for building REST and GraphQL APIs that follow proven conventions. ## Core Features & Use Cases - REST Design Patterns: Resource-oriented endpoints, correct HTTP method semantics, pagination, filtering, HATEOAS links, and standardized error responses with proper status codes. - GraphQL Design Patterns: Schema-first development, Relay-style cursor pagination, mutation payloads with structured errors, and DataLoader usage to prevent N+1 queries. - Versioning & Standards: Guidance on URL, header, and query-parameter versioning plus best-practice checklists for rate limiting, documentation, and deprecation. - Use Case: When reviewing a new FastAPI endpoint specification, apply the pagination and error-handling patterns to return consistent PaginatedResponse objects and structured 404 errors before implementation begins. ## Quick Start Ask the AI to review your API endpoint design or generate a REST or GraphQL schema for your resource model using these design principles.

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 RESTful API endpoints correctly?▼

Use plural nouns for resources (e.g., /api/users) and HTTP methods for actions: GET to retrieve, POST to create, PUT to replace, PATCH to update, and DELETE to remove. Avoid action-oriented URLs like /api/createUser, and nest related resources such as /api/users/{id}/orders.

How to implement pagination in a REST API?▼

Accept page and page_size query parameters with validation bounds, then return a response containing items, total count, current page, and total pages. The FastAPI example uses Query parameters with ge/le constraints and computes offset as (page - 1) * page_size.

REST vs GraphQL: which should I use for my API?▼

REST suits resource-oriented services with standard CRUD operations and HTTP caching, while GraphQL lets clients request exactly the fields they need through a single typed endpoint. GraphQL requires DataLoaders to avoid N+1 query problems, whereas REST can suffer from over-fetching and under-fetching.

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

Use the DataLoader pattern to batch and cache database fetches per request. Implement a batch_load_fn that accepts a list of IDs, fetches all matching records in one query, and returns results mapped to the original ID order.

What HTTP status codes should a REST API return?▼

Return 200 for success, 201 for creation, 204 for no content, 400 for bad requests, 401 for unauthorized, 403 for forbidden, 404 for not found, 409 for conflicts, 422 for validation errors, and 500 for server errors. Pair errors with a structured body containing error type, message, and details.

When should I version my API and how?▼

Version your API from day one to plan for breaking changes. Options include URL versioning (/api/v1/users), header versioning via the Accept header, or query parameter versioning; GraphQL APIs typically evolve through schema deprecation instead of explicit versions.