Request & Response Structure
- JSON is the default interchange for REST; define schemas (OpenAPI, JSON Schema) for fields and nullability.
- Use consistent date/time (ISO 8601 UTC) and money representations (minor units or decimal strings) and document them.
- Avoid sending huge blobs inline when streaming or separate download URLs fit better.
- Content-Type and Accept declare payloads; for JSON APIs use
application/json unless you negotiate others.
- Authorization carries credentials (Bearer tokens, signatures); never log secrets.
- Use trace/correlation headers (
X-Request-Id, W3C traceparent) for supportability.
Query params vs path params vs body
- Path params identify the resource (
/users/{id}).
- Query params filter, sort, paginate, and toggle sparse field sets.
- Body carries create/update payloads (POST/PUT/PATCH) and complex search criteria when query strings get unwieldy.
- Wrap list endpoints with pagination metadata (cursor or offset/limit) in a predictable envelope.
- Use a standard error object (
code, message, details, requestId) across the API.
- Prefer stable field names; avoid renaming without versioning or deprecation windows.