4.5.6 · D3Software Engineering

Worked examples — REST API design — resources, HTTP methods, status codes, versioning, pagination

3,072 words14 min readBack to topic

Before we start, one word we'll lean on constantly:


The scenario matrix

Every REST interaction lands in exactly one of these cells. Read it as: what is the client trying to do, and what unusual condition makes the answer non-obvious.

# Case class The tricky condition Worked in
A Create (server assigns id) success path, Location header Ex 1
B Create — duplicate resource already exists (conflict) Ex 2
C Partial update change one field, don't wipe others Ex 3
D Full replace vs partial omitted field gets defaulted Ex 3
E Delete, then retry idempotency after a timeout Ex 4
F Auth failures who-are-you vs you-can't (401 vs 403) Ex 5
G Validation malformed (400) vs semantically wrong (422) Ex 6
H Pagination — offset, normal page → offset arithmetic Ex 7
I Pagination — empty / last partial / invalid page remainder rows, zero results, page 0 Ex 7
J Pagination — live data inserts shift rows → cursor fix Ex 8
K Pagination — deep offset performance limit, jump vs stream Ex 8
L Versioning breaking change forces /v2 Ex 9

The 9 examples below hit all 12 cells (some examples cover two related cells).


Worked examples










Recall Quick self-test

Page size 10, 23 items — how many pages? ::: (the last page holds only 3 rows). Offset for page 5 at size 20? ::: . A request for page 0 — what status? ::: 400 Bad Request (invalid input; offset would be negative), not an empty 200. Timed-out DELETE retried — safe? ::: Yes, DELETE is idempotent; final state is identical, and 204 on the retry reports that success. Which header must a 401 carry? ::: WWW-Authenticate (RFC 7235) — it tells the client which auth scheme to use. Valid JSON but age=-5 — which code? ::: 422 Unprocessable Entity (parsed, but semantically invalid). No token vs wrong permission? ::: 401 (unauthenticated) vs 403 (forbidden). Empty last page — 404 or 200? ::: 200 with an empty list; the collection exists.