What is the usefulness of PUT and DELETE HTTP request methods?
I have read a lot stuff about this but not able to get the conclusion on this topic.
But I've never used PUT or DELETE HTTP Request methods. My tendency is to use GET when stat of the system(my application or website) may not be affected (like product listing) and to use POST when it is affected(order placed). Isn't it sufficient or am I missing something ?
DELETE is for deleting the request resource:
The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully …
PUT is for putting or updating a resource on the server:
The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI …
For the full specification visit:
or even worse
effectively tunneling CRUD semantics over HTTP. But verbs were never meant to be part of the URI. Instead HTTP already provides the mechanism and semantics to CRUD a Resource (e.g. an order) through the HTTP methods. HTTP is a protocol and not just some data tunneling service.
So to delete a Resource on the webserver, you'd call
and to update it you'd call
and provide the updated Resource Representation in the PUT body for the webserver to apply then.
For some more details visit:
- Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
- Why are there no PUT and DELETE methods in HTML forms
- Should PUT and DELETE be used in forms?
Using HTTP Request verb such as GET, POST, DELETE, PUT etc... enables you to build RESTful web applications. Read about it here: http://en.wikipedia.org/wiki/Representational_state_transfer
The easiest way to see benefits from this is to look at this example. Every MVC framework has a Router/Dispatcher that maps URL-s to actionControllers. So URL like this: /blog/article/1 would invoke blogController::articleAction($id); Now this Router is only aware of the URL or /blog/article/1/
But if that Router would be aware of whole HTTP Request object instead of just URL, he could have access HTTP Request verb (GET, POST, PUT, DELETE...), and many other useful stuff about current HTTP Request.
That would enable you to configure application so it can accept the same URL and map it to different actionControllers depending on the HTTP Request verb.
if you want to retrive article 1 you can do this:
GET /blog/article/1 HTTP/1.1
but if you want to delete article 1 you will do this:
DELETE /blog/article/1 HTTP/1.1
Notice that both HTTP Requests have the same URI, /blog/article/1, the only difference is the HTTP Request verb. And based on that verb your router can call different actionController. This enables you to build neat URL-s.
Read this two articles, they might help you:
These articles are about Symfony 2 framework, but they can help you to figure out how does HTTP Requests and Responses work.
Hope this helps!
Safe Methods : Get Resource/No modification in resource Idempotent : No change in resource status if requested many times Unsafe Methods : Create or Update Resource/Modification in resource Non-Idempotent : Change in resource status if requested many times
According to your requirement :
1) For safe and idempotent operation (Fetch Resource) use --------- GET METHOD 2) For unsafe and non-idempotent operation (Insert Resource) use--------- POST METHOD 3) For unsafe and idempotent operation (Update Resource) use--------- PUT METHOD 3) For unsafe and idempotent operation (Delete Resource) use--------- DELETE METHOD