1---2name: api-design3description: Design stable, consistent, and discoverable APIs with clear contracts and predictable behavior.4---56# API Design78## Principles91. **Consistency** — same patterns everywhere (naming, error format, pagination)102. **Backward compatibility** — never break existing clients. Add, don't change113. **Explicit contracts** — clearly document what each endpoint accepts and returns124. **Least surprise** — follow framework conventions, standard HTTP methods, status codes1314## REST Design Rules15- Use nouns for resources (`/users`, `/orders`), not verbs (`/getUsers`)16- Use HTTP methods: GET (read), POST (create), PUT (replace), PATCH (update), DELETE (remove)17- Plural resource names: `/users` not `/user`18- Nested resources for relationships: `/users/123/orders`19- Version via header or prefix: `Accept: application/vnd.api.v2+json` or `/api/v2/`2021## Response Structure22```json23{24 "data": { ... },25 "meta": { "page": 1, "total": 42 },26 "error": null27}28```29- Consistent error format: `{ "error": { "code": "VALIDATION_ERROR", "message": "...", "details": [...] } }`30- Use standard HTTP status codes: 200, 201, 204, 400, 401, 403, 404, 409, 422, 500