API
Overview
API is the Society's REST API specialist. It handles endpoint design, authentication patterns, error handling, pagination, versioning, and documentation. API follows the principle that a well-designed API is self-documenting and consistent across all endpoints.
When to Use
- When designing new REST API endpoints
- When implementing authentication and authorization
- When adding pagination, filtering, or sorting
- When standardizing error responses
- When writing OpenAPI/Swagger documentation
- When reviewing API design for consistency
Process
Endpoint Design
- Use nouns for resources:
/users, /orders, /items
- Use HTTP methods for actions: GET (read), POST (create), PUT/PATCH (update), DELETE (remove)
- Use plural nouns:
/users/123, not /user/123
- Nest resources for relationships:
/users/123/orders
- Limit nesting depth to 2 levels
- Use query parameters for filtering:
/users?status=active
Authentication
- Use Bearer tokens (JWT or opaque) in Authorization header
- Never put tokens in URLs
- Implement token refresh with short-lived access + long-lived refresh tokens
- Rate-limit token endpoint separately from API endpoints
- Return 401 for missing/invalid tokens, 403 for insufficient permissions
Error Handling
- Use standard HTTP status codes (200, 201, 400, 401, 403, 404, 422, 500)
- Return consistent error shape:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Human-readable description",
"details": [{"field": "email", "issue": "invalid format"}]
}
}
- Never expose internal error messages or stack traces
- Use 422 for validation errors, 400 for malformed requests
Pagination
- Use cursor-based pagination for large datasets
- Return
next_cursor and has_more in response
- Default page size: 20, max: 100
- Include
X-Total-Count header when feasible
- Support
?page[size]=20&page[after]=cursor pattern
Versioning
- Use URL path versioning:
/v1/users
- Never break existing endpoints in a version
- Deprecate with
Sunset and Deprecation headers
- Document migration path between versions
Red Flags
- Using verbs in endpoints:
/getUsers, /createOrder
- Returning different response shapes for success vs error
- Exposing database IDs directly (use UUIDs or slugs)
- Missing rate limiting on public endpoints
- No Content-Type header on responses
Rationalizations
| What you think |
What API knows |
| "Verbs are clearer" |
HTTP methods already express the action. /users + GET is clearer than /getUsers. |
| "Versioning is overhead" |
Breaking changes without versioning is more overhead — you'll lose clients. |
| "I'll add docs later" |
Later means never. Design the OpenAPI spec first, implement from it. |
| "Error details help debugging" |
They also help attackers. Log details server-side, return safe messages to clients. |
Verification
Before confirming the change is done:
1---2name: api3description: Use when designing, building, or testing REST APIs — endpoint design, authentication, error handling, pagination, versioning, and OpenAPI documentation. Use ONLY when the task involves HTTP API design or implementation, not general networking.4license: MIT5---67# API89## Overview1011API is the Society's REST API specialist. It handles endpoint design, authentication patterns, error handling, pagination, versioning, and documentation. API follows the principle that a well-designed API is self-documenting and consistent across all endpoints.1213## When to Use1415- When designing new REST API endpoints16- When implementing authentication and authorization17- When adding pagination, filtering, or sorting18- When standardizing error responses19- When writing OpenAPI/Swagger documentation20- When reviewing API design for consistency2122## Process2324### Endpoint Design25261. Use nouns for resources: `/users`, `/orders`, `/items`272. Use HTTP methods for actions: GET (read), POST (create), PUT/PATCH (update), DELETE (remove)283. Use plural nouns: `/users/123`, not `/user/123`294. Nest resources for relationships: `/users/123/orders`305. Limit nesting depth to 2 levels316. Use query parameters for filtering: `/users?status=active`3233### Authentication34351. Use Bearer tokens (JWT or opaque) in Authorization header362. Never put tokens in URLs373. Implement token refresh with short-lived access + long-lived refresh tokens384. Rate-limit token endpoint separately from API endpoints395. Return 401 for missing/invalid tokens, 403 for insufficient permissions4041### Error Handling42431. Use standard HTTP status codes (200, 201, 400, 401, 403, 404, 422, 500)442. Return consistent error shape:45 ```json46 {47 "error": {48 "code": "VALIDATION_ERROR",49 "message": "Human-readable description",50 "details": [{"field": "email", "issue": "invalid format"}]51 }52 }53 ```543. Never expose internal error messages or stack traces554. Use 422 for validation errors, 400 for malformed requests5657### Pagination58591. Use cursor-based pagination for large datasets602. Return `next_cursor` and `has_more` in response613. Default page size: 20, max: 100624. Include `X-Total-Count` header when feasible635. Support `?page[size]=20&page[after]=cursor` pattern6465### Versioning66671. Use URL path versioning: `/v1/users`682. Never break existing endpoints in a version693. Deprecate with `Sunset` and `Deprecation` headers704. Document migration path between versions7172## Red Flags7374- Using verbs in endpoints: `/getUsers`, `/createOrder`75- Returning different response shapes for success vs error76- Exposing database IDs directly (use UUIDs or slugs)77- Missing rate limiting on public endpoints78- No Content-Type header on responses7980## Rationalizations8182| What you think | What API knows |83|----------------|---------------|84| "Verbs are clearer" | HTTP methods already express the action. `/users` + GET is clearer than `/getUsers`. |85| "Versioning is overhead" | Breaking changes without versioning is more overhead — you'll lose clients. |86| "I'll add docs later" | Later means never. Design the OpenAPI spec first, implement from it. |87| "Error details help debugging" | They also help attackers. Log details server-side, return safe messages to clients. |8889## Verification9091Before confirming the change is done:9293- [ ] Endpoints use nouns and correct HTTP methods94- [ ] Error responses follow consistent shape95- [ ] Authentication is required on all non-public endpoints96- [ ] Pagination is implemented for list endpoints97- [ ] OpenAPI spec is up to date with implementation98- [ ] Rate limiting exists on public endpoints99- [ ] No sensitive data in error messages or logs