✂️ REST

Small information nuggets and recipies about REST


(most recent on top)

Response codes and bodies

204s are mostly for deletes. since posts usually return 201s and both puts and gets return bodies on the responses

Nuno Marques

Verbs, their meaning and usage

… POST = Create

# Entire Collection e.g. /customers
201 Created
'Location' header with link to /customers/{id} containing the new ID
# Specific Item e.g. /customers/{id}
404 Not Found
409 Conflict — if resource already exists

… GET = Read

# Entire Collection e.g. /customers
200 OK
List of customers (use pagination, sorting and filtering on big lists)
# Specific Item e.g. /customers/{id}
200 OK — single customer
404 Not Found — if ID not found or invalid

… PUT = Update / Replace

# Entire Collection e.g. /customers
404 Not Found — unless you want to update/replace every resource in the entire collection
# Specific Item e.g. /customers/{id}
200 OK
201 Created — if using PUT for create, no need for a Location header
204 No Content
404 Not Found — if ID not found or invalid

… PATCH = Update / Modify

# Entire Collection e.g. /customers
404 Not Found — unless you want to modify the collection itself
# Specific Item e.g. /customers/{id}
200 OK
204 No Content
404 Not Found — if ID not found or invalid

… DELETE = Delete

# Entire Collection e.g. /customers
404 Not Found — unless you want to delete the whole collection
# Specific Item e.g. /customers/{id}
200 OK — maybe along with a response body if describing the status
202 Accepted — if the action has not yet been enacted
204 No Content — with no response body
404 Not Found — if ID not found or invalid