home / skills / maxritter / pilot-shell / standards-api

standards-api skill

/.claude/ccp/skills/standards-api

This skill helps design and implement RESTful API endpoints using proper HTTP methods, status codes, and resource-based URLs.

npx playbooks add skill maxritter/pilot-shell --skill standards-api

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
5.6 KB
---
name: standards-api
description: Design and implement RESTful API endpoints following REST principles with proper HTTP methods, status codes, and resource-based URLs. Use this skill when creating or modifying API endpoints, route handlers, controllers, or API configuration files. Apply when working on REST API design, endpoint implementations, API versioning, request/response handling, HTTP method routing (GET, POST, PUT, PATCH, DELETE), query parameter filtering, API rate limiting, or any file that defines API routes such as routes.py, api.js, controllers/, endpoints/, or API documentation files.
---

# API Standards

Apply these standards when creating or modifying API endpoints, route handlers, and controllers.

## When to use this skill

- When creating or modifying API endpoint files (routes.py, api.js, controllers/, endpoints/, etc.)
- When implementing REST API route handlers and controllers
- When designing resource-based URL structures and HTTP method routing
- When working with API versioning strategies in URL paths or headers
- When implementing query parameters for filtering, sorting, pagination, or search
- When configuring HTTP status codes for API responses
- When setting up rate limiting headers or API middleware
- When writing API documentation or OpenAPI/Swagger specifications
- When refactoring existing API endpoints for consistency or REST compliance

This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle backend API.

## RESTful Design Principles

**Resource-based URLs with HTTP methods:**
- `GET /users` - List users
- `GET /users/{id}` - Get specific user
- `POST /users` - Create user
- `PUT /users/{id}` - Replace user (full update)
- `PATCH /users/{id}` - Update user (partial update)
- `DELETE /users/{id}` - Delete user

**Use plural nouns for collections:**
- ✅ `/users`, `/products`, `/orders`
- ❌ `/user`, `/product`, `/order`

**Limit nesting to 2-3 levels:**
- ✅ `/users/{id}/orders`
- ✅ `/users/{id}/orders/{order_id}`
- ❌ `/users/{id}/orders/{order_id}/items/{item_id}/reviews`

## URL and Naming Conventions

**Consistent casing:**
- Use lowercase with hyphens: `/user-profiles` or underscores: `/user_profiles`
- Never mix: ❌ `/userProfiles`, ❌ `/User-Profiles`
- Check existing endpoints first and match the project's convention

**Query parameters for operations:**
- Filtering: `GET /users?status=active&role=admin`
- Sorting: `GET /users?sort=created_at&order=desc`
- Pagination: `GET /users?page=2&limit=50` or `?offset=100&limit=50`
- Search: `GET /users?q=john`

**Avoid creating separate endpoints for these operations.**

## HTTP Status Codes

Return accurate status codes:

**Success:**
- `200 OK` - Successful GET, PUT, PATCH, DELETE
- `201 Created` - Successful POST (include `Location` header)
- `204 No Content` - Successful DELETE with no response body

**Client Errors:**
- `400 Bad Request` - Invalid input, validation failure
- `401 Unauthorized` - Missing or invalid authentication
- `403 Forbidden` - Authenticated but not authorized
- `404 Not Found` - Resource doesn't exist
- `409 Conflict` - Duplicate resource, constraint violation
- `422 Unprocessable Entity` - Semantic validation failure

**Server Errors:**
- `500 Internal Server Error` - Unexpected server error
- `503 Service Unavailable` - Temporary unavailability

## API Versioning

**Choose one strategy and apply consistently:**

URL path versioning (recommended for simplicity):
```
/v1/users
/v2/users
```

Header versioning (for cleaner URLs):
```
Accept: application/vnd.api.v1+json
```

**When to version:**
- Breaking changes to request/response format
- Removing fields or endpoints
- Changing field types or validation rules

**Don't version for:**
- Adding optional fields
- Adding new endpoints
- Bug fixes

## Request/Response Patterns

**Consistent response structure:**
```json
{
  "data": { "id": 1, "name": "John" },
  "meta": { "timestamp": "2024-01-01T00:00:00Z" }
}
```

**Error response structure:**
```json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input",
    "details": [
      { "field": "email", "message": "Invalid email format" }
    ]
  }
}
```

**Pagination metadata:**
```json
{
  "data": [...],
  "pagination": {
    "page": 2,
    "limit": 50,
    "total": 250,
    "pages": 5
  }
}
```

## Rate Limiting

**Include rate limit headers:**
```
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200
```

Return `429 Too Many Requests` when limit exceeded.

## Validation and Error Handling

**Validate at API boundary:**
- Check required fields before processing
- Validate formats (email, phone, URL)
- Enforce business rules
- Return specific error messages

**Never expose internal errors to clients:**
- ❌ Database error messages
- ❌ Stack traces
- ❌ Internal file paths
- ✅ Generic "Internal server error" with request ID for tracking

## Documentation

**Document each endpoint:**
- Purpose and use case
- Request parameters and body schema
- Response schema and status codes
- Authentication requirements
- Rate limits
- Example requests/responses

Use OpenAPI/Swagger for machine-readable documentation.

## Before Completing API Work

- [ ] Endpoints follow REST principles
- [ ] URLs use consistent naming convention
- [ ] HTTP methods match operations (GET for read, POST for create, etc.)
- [ ] Status codes accurately reflect responses
- [ ] Validation happens at API boundary
- [ ] Error responses are structured and specific
- [ ] Rate limiting headers included (if applicable)
- [ ] Documentation updated
- [ ] Tests cover success and error cases

Overview

This skill enforces RESTful API design and implementation standards for route handlers, controllers, and API configuration files. It ensures resource-based URLs, correct HTTP methods and status codes, consistent versioning, request/response shapes, and careful error handling. Use it to make APIs predictable, maintainable, and production-ready.

How this skill works

The skill inspects route and controller files (routes.py, api.js, controllers/, endpoints/, etc.) and validates that URLs use plural, resource-based patterns, HTTP methods map to CRUD semantics, and nesting is limited. It checks status codes, response and error structures, pagination and filtering query conventions, versioning strategy, and presence of rate limit headers and documentation. It flags violations and suggests concrete corrections.

When to use it

  • Creating or modifying API endpoints, route handlers, or controllers
  • Designing resource-based URL structures and HTTP method routing
  • Implementing query params for filtering, sorting, pagination, or search
  • Applying API versioning (URL or header strategy) or changing contracts
  • Adding rate limiting, validation, or consistent error handling
  • Writing or updating OpenAPI/Swagger documentation for the API

Best practices

  • Use plural resource names and limit nesting to 2-3 levels (e.g., /users/{id}/orders)
  • Map HTTP verbs to semantics: GET for read, POST create, PUT replace, PATCH partial update, DELETE remove
  • Return accurate status codes (201 on create with Location, 204 on successful delete with no body)
  • Keep consistent response and error schemas with data/meta and structured error objects
  • Validate at the API boundary and never leak internal errors; include a request ID for troubleshooting
  • Document endpoints, request/response schemas, auth requirements, and rate limits using OpenAPI

Example use cases

  • Refactor a mixed-case endpoint set to a consistent kebab-case or snake_case naming convention
  • Add pagination, sorting, and filtering to a large collection endpoint using query params
  • Implement versioning for a breaking change to a response contract (e.g., /v2/users)
  • Standardize error responses and map service errors to appropriate HTTP status codes
  • Add rate limit headers and a 429 response path for high-volume endpoints

FAQ

When should I create a new API version?

Introduce a new version only for breaking changes to request/response formats, removed fields, or changed field types. Additive changes and bug fixes do not require versioning.

Should I use URL or header versioning?

URL path versioning is simpler and recommended for most APIs. Use header versioning when you must keep URLs clean and can enforce header requirements consistently.