REST API Best Practices and Anti-Patterns

High-signal design rules, consistency patterns, and common mistakes to avoid in production APIs.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Best practices

Design choices that improve consistency and developer experience.

Keep response contracts consistent

Use the same top-level response structure across endpoints.

textANYrestconsistencyresponses
text
List endpoints should return a predictable structure for data, pagination, and errors.

Consistency lowers cognitive load and makes SDKs, docs, and client code easier to maintain.

Return a request ID

Make support and debugging easier.

httpANYrestobservabilityrequest-id
http
X-Request-Id: req_01HXYZ123

A request identifier lets support teams correlate API failures with logs and traces quickly.

Use ISO 8601 timestamps

Prefer explicit timezone-aware datetime strings.

textANYresttimestampsiso8601
text
2026-03-27T22:15:00Z

ISO 8601 timestamps are broadly interoperable and less ambiguous than locale-formatted date strings.

Document rate limits clearly

Help clients back off safely.

httpANYrestrate-limitsheaders
http
RateLimit-Limit: 100
RateLimit-Remaining: 24
RateLimit-Reset: 60

Returning limit metadata helps clients self-throttle and debug rate-limit behavior.

Provide copy-paste examples

Show real requests and responses in docs.

bashANYrestdocscurl
bash
curl -X GET https://api.example.com/v1/users/usr_123 \
  -H "Authorization: Bearer $TOKEN"

Concrete examples reduce onboarding friction and improve the usefulness of documentation and cheat sheets.

Anti-patterns

Common API design mistakes that age poorly.

Verbs in CRUD endpoints

Avoid route names that duplicate the HTTP method.

textANYrestanti-patternroutes
text
Avoid: POST /createUser
Prefer: POST /users

Using verbs in CRUD endpoints usually leads to inconsistent route shapes and redundant semantics.

Do not return 200 for every outcome

Use HTTP status codes meaningfully.

textANYrestanti-patternstatus-codes
text
Avoid: HTTP 200 with { "success": false } for validation failures

Meaningful status codes help caches, clients, SDKs, observability tools, and humans interpret results correctly.

Do not expose raw database internals

Keep API models stable and intentional.

textANYrestanti-patterndomain-model
text
Avoid exposing internal table names, join tables, and migration-driven field names directly.

An API contract should reflect domain concepts, not your current storage layout.

Do not ship breaking changes silently

Version or phase in incompatible changes.

textANYrestanti-patternversioning
text
Avoid removing fields or changing meanings without deprecation and migration guidance.

Silent breaking changes erode trust and create hard-to-debug production failures for clients.

Avoid deeply nested routes

Keep URLs maintainable.

textANYrestanti-patternnesting
text
Avoid: /orgs/{orgId}/teams/{teamId}/projects/{projectId}/tickets/{ticketId}/comments

Very deep routes make identity, authorization, and caching rules harder to reason about.

Recommended next

No recommendations yet.