--- description: REST API design — routes, responses, versioning, and validation globs: **/api/**/*.{ts,js,py,go},**/routes/**/*.{ts,js,py} alwaysApply: false --- # REST API Design - Use nouns for resources (`/users`, `/orders`), HTTP verbs for actions. - Plural resource names. Nested resources only when truly parent-scoped (`/users/{id}/orders`). - Return consistent JSON envelopes: `{ data, error, meta }` or match existing project pattern. - Paginate list endpoints: `limit`, `offset` or cursor-based. Include total count when cheap. - Version breaking APIs (`/v1/`, `/v2/`) — never break clients silently. - Validate request bodies with a schema (Zod, Pydantic, etc.) before business logic. - Use `201 Created` + `Location` header on resource creation. - Use `204 No Content` for successful deletes with no body. - Document error response shapes. Same error format across all endpoints. - Rate-limit public and auth endpoints.