what's the advantage of using put and delete a

2019-04-26 19:59发布

问题:

Especially for the majority of browsers that don't support it, is there anything aside from just strict standards compliance that justifies the extra development time?

回答1:

If you develop your web application only for browser, you should go with post and get.

But e.g. REST-APIs should/could make use of the put and delete methods. So you could better define what action you want to execute on special resources. http://en.wikipedia.org/wiki/Representational_State_Transfer



回答2:

There's a pretty interesting article on this very subject here: http://www.artima.com/lejava/articles/why_put_and_delete.html

A slight extract:

PUT and DELETE are in the middle between GET and POST. The difference between PUT or DELETE and POST is that PUT and DELETE are idempotent, whereas POST is not. PUT and DELETE can be repeated if necessary. Let's say you're trying to upload a new page to a site. Say you want to create a new page at http://www.example.com/foo.html, so you type your content and you PUT it at that URL. The server creates that page at that URL that you supply. Now, let's suppose for some reason your network connection goes down. You aren't sure, did the request get through or not? Maybe the network is slow. Maybe there was a proxy server problem. So it's perfectly OK to try it again, or again—as many times as you like. Because PUTTING the same document to the same URL ten times won't be any different than putting it once. The same is true for DELETE. You can DELETE something ten times, and that's the same as deleting it once.