What is the difference between HTTP GET, POST, PUT, and DELETE methods

I am developing a REST WCF service, and, theoretically, I know when to choose what purpose.

  • GET to get a resource
  • PUT to update
  • POST for input
  • DELETE to delete

But what is the drawback if we do not follow the rule above, suppose I used the GET method to insert a record?

+39
rest web-services wcf
Aug 23 '13 at 5:39 on
source share
3 answers

Because the HTTP GET method is listed as idempotent, the specification GET request can be resubmitted with the assumption that it will not change anything on the server. This does not apply to HTTP POST, which, by specification, can change the status of an application running on a server.

Thus, by specification, you can perform an HTTP GET against page N the number of times, without worrying about changing your status.

Failure to comply with the specification may have various undesirable results. For example, web crawlers follow a GET request to index the site, but not POST. If you allow the HTTP GET request to make changes to the database, you can easily understand the unwanted implication that it may have.

Respect for the specification is in compliance with the agreement between your service or website and many different consumers, which can be ordinary browsers of users, as well as other services, such as web scanners.

You can create a site that uses GET to insert a record, but you should also expect that everything that is built around to consume your site works with the assumption that you are complying with the agreement.

As a final example, web browsers warn users when they try to refresh a page that was reached by an HTTP POST request, warning that some data may be re-sent. You do not get this level of protection for embedded browsers if the page is reached with an HTTP GET request.

You can read more here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

+48
Aug 23 '13 at 5:59 on
source

But what is the drawback if we do not follow the rule above, suppose I used the GET method to insert the record.

Search engines access your pages using GET requests, so if you do, a Google crawler can insert posts that you donโ€™t need.

Often people will use POST for any ajax request, with the actual action in the request body. There is nothing wrong with that, but there is a function here, so you can use it.

+10
Aug 23
source

I ran into a situation, I had to use PUT instead of GET. I had a request to enter permission to third parties (it was Google). I am twisting an Ajax GET request to request an update permission for my servlet, and from their call I switched to an external service. An external service took a considerable amount of time to complete the request. At the same time, I saw duplication of the same permission in my server logs. Is it a browser that keeps calling the server saying what you did? since it is a GET, and the browser can call the server as many times as possible. The browser followed the standard, but my code did not. I had a problem not for the standard one.

+3
Oct 17 '14 at 15:14
source



All Articles