RESTful HTTP Verbs
HTTP verbs POST, GET, PUT, PATCH and DELETE correspond to create, read, update and delete (CRUD) operations. Below is a table summarizing recommended return values of the primary HTTP methods in combination with the resource URIs:
HTTP Verb | CRUD | Entire Collection (e.g. /orders) | Specific Item (e.g. /orders/) |
---|---|---|---|
POST | Create | 201 (Created), 'Location' header with link to /orders/ containing new ID. | 200 (OK), list of orders. Use pagination, sorting and filtering to navigate big lists. |
GET | Read | 200 (OK), list of orders. Use pagination, sorting and filtering to navigate big lists. | 200 (OK), single order. 404 (Not Found), if ID not found or invalid. |
PUT | Update/Replace | 404 (Not Found), unless you want to update/replace every resource in the entire collection. | 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid. |
PATCH | Update/Modify | 404 (Not Found), unless you want to modify the collection itself. | 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid. |
DELETE | Delete | 404 (Not Found), unless you want to delete the whole collection—not often desirable. | 200 (OK). 404 (Not Found), if ID not found or invalid. |