REST API Design Patterns Cheat Sheet

RESTful API design principles: HTTP methods, resource naming conventions, status code usage, authentication patterns, versioning strategies, and pagination.

Last Updated: May 1, 2025

HTTP Methods & Resources

ItemDescription
GET /usersList users collection (paginated)
GET /users/123Retrieve single user
POST /usersCreate a new user (body contains resource)
PUT /users/123Full replacement of user 123
PATCH /users/123Partial update of user 123
DELETE /users/123Remove user 123
HEAD /users/123Get headers only (check existence, Last-Modified)
OPTIONS /usersDiscover allowed methods (CORS preflight)

Status Codes for APIs

ItemDescription
200 OKSuccessful GET, PUT, PATCH
201 CreatedSuccessful POST — include Location header with new URL
202 AcceptedAsync operation queued — return status endpoint
204 No ContentSuccessful DELETE (no body)
400 Bad RequestMalformed JSON, invalid query parameters
401 UnauthorizedMissing or invalid authentication
403 ForbiddenValid auth but insufficient permissions
404 Not FoundResource doesn't exist
409 ConflictDuplicate or version conflict (optimistic locking)
422 UnprocessableValidation errors — return structured error details
429 Too Many RequestsRate limit — include Retry-After and X-RateLimit-* headers

Authentication Patterns

ItemDescription
API KeysSimple: X-API-Key header. Good for server-to-server. Rotatable.
Bearer Token (JWT)Stateless auth with claims. Use short expiry + refresh tokens.
OAuth 2.0Delegated authorization. Authorization Code flow for user-facing apps.
HMAC SigningValidates integrity + identity via signed request (AWS Signature V4)
mTLSMutual TLS — both client and server present certificates

Versioning & Pagination

ItemDescription
URL versioning/v1/users (most explicit, easy to route)
Header versioningAccept: application/vnd.api.v1+json (cleaner URLs)
Query param/users?version=1 (simple but pollutes URL)
Offset pagination?offset=0&limit=20 (simple but drifts on inserts)
Cursor pagination?cursor=abc123&limit=20 (stable, recommended)
Link headerStandard: Link: ; rel="next" for discoverable pagination
Pro Tip: Use plural nouns for collections: /users not /getUsers. Nest resources sparingly — max 1 level deep (/users/123/orders is fine; /users/123/orders/456/items is not).