GET: safe, idempotent, 200. POST: no, no, 201 + Location. PUT: not safe, idempotent, 200/204 (201 if created). PATCH: no, no (in general), 200/204. DELETE: not safe, idempotent, 204.
2
New cards
Safe vs idempotent: the relationship.
Every safe method is idempotent; not every idempotent method is safe (PUT, DELETE change state).
3
New cards
POST vs PUT for creating.
POST to the collection, the server picks the ID (POST /orders). PUT to the exact URI the client knows (PUT /orders/42).
4
New cards
PUT vs PATCH.
PUT sends the whole resource (missing fields are cleared). PATCH sends only the changes. Partial update → PATCH.
Requests get bigger and "chattier" (each carries its auth token and context).
9
New cards
URI design rules.
Nouns not verbs (/orders, not /createOrder); plural collections + ID (/rides/{id}); nesting shows ownership (/users/{id}/rides); filters/sort/paging in the query string; lower case, hyphens, no file extensions; version /v1/.
10
New cards
Template for a REST design answer (2 marks per endpoint).
Method + URI + request body + success code + main error codes (400, 401/403, 404, 409).
11
New cards
Design: create a ride request (sample paper).
POST /v1/rides with JSON {riderId, pickup, dropoff, requestedAt} + Authorization: Bearer token → 201 Created, Location: /v1/rides/R789; 400 invalid fields, 401 no token.
12
New cards
Design: update ride status (sample paper).
PATCH /v1/rides/R789 {"status": "completed"} → 200 with the ride (or 204); 404 no such ride, 409 illegal transition, 403 not this ride's driver.
13
New cards
Richardson levels 0–3.
0 one endpoint, operation in the body (SOAP-like) · 1 a URI per resource · 2 HTTP verbs + status codes · 3 hypermedia (HATEOAS).
14
New cards
Why HATEOAS?
The server can change URIs without breaking clients, and the API documents itself: clients follow links to the next actions.
15
New cards
Caching makes an API "work-shy": what does that mean, and the two conditional request pairs?
Data is sent only when needed. ETag + If-None-Match → 304; Last-Modified + If-Modified-Since → 304.
16
New cards
A good API is "clean, clear, consistent": what does that mean?
A developer can understand it without studying the docs: predictable nouns, standard methods, consistent codes and formats.
17
New cards
Writing a REST client: the steps.
Read the docs → send requests (requests.get/post) → always check the status code and handle errors → parse JSON → cache responses to save calls and stay under rate limits.