The Rest is Silence...Not yet? Mapping CRUD methods to HTTP methods for RESTful Services
The most useful HTTP methods are four methods: POST, GET, PUT, and DELETE.
These correspond to create, read, update, and delete (generally speaking CRUD) operations.
We can also use OPTIONS and HEAD sometimes as HTTP methods...
Recommended return values (http://www.restapitutorial.com/httpstatuscodes.html)
of four most useful REST HTTP methods are as follows:
With an entire Collection (e.g. /products):
HTTP Method/Verb
GET 200 (OK), list of products. Use pagination, sorting and filtering to navigate big lists.
PUT 404 (Not Found), unless you want to update/replace every resource in the entire collection.
POST 201 (Created), 'Location' header with link to /products/{id} containing new ID.
DELETE 404 (Not Found), unless you want to delete the whole collection—not often desirable.
With a specific Item (e.g. /products/{id}):
HTTP Method/Verb
GET 200 (OK), single product. 404 (Not Found), if ID not found or invalid.
PUT 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
POST 404 (Not Found).
DELETE 200 (OK). 404 (Not Found), if ID not found or invalid.
Summarizing up:
Create --> POST to a base URI returning a newly created URI
PUT with a new URI
Read --> GET
Update --> PUT with an existing URI
Delete --> DELETE
GET (along with HEAD) requests are used only to read data and not change it.
Do not expose unsafe operations via GET. It should never modify any resources on the server.
PUT is not a safe operation, in that it modifies (or creates) state on the server, but it is idempotent.
In other words, if you create or update a resource using PUT and then make that same call again,
the resource is still there and still has the same state as it did with the first call.
It is recommended to keep PUT requests idempotent.
It is strongly recommended to use POST for non-idempotent requests.
The POST verb is most-often utilized for creation of new resources.
POST is neither safe nor idempotent.
It is therefore recommended for non-idempotent resource requests.
Making two identical POST requests will most-likely result in two resources containing the same information.
DELETE is pretty easy to understand. It is used to delete a resource identified by a URI.
There is a caveat about DELETE idempotence, however.
Calling DELETE on a resource a second time will often return a 404 (NOT FOUND) since
it was already removed and therefore is no longer findable.