-2

We can delete a value from a database if that value is send using POST to another page and then firing delete query, then what is the difference between POST and DELETE in this case?

  • HTTP Headers are mostly conventions, In theory you could delete your entire database when someone GETs your page – Shogunivar Mar 14 '17 at 07:42
  • 2
    See here - http://stackoverflow.com/questions/18395523/what-is-difference-between-http-methods-get-post-put-and-delete – Brett Gregson Mar 14 '17 at 07:43
  • Thanks. I got this point. But can you answer this in a bit simple language? – Mohit Bansal Mar 14 '17 at 07:47
  • In your case, the difference lie on "semantic". As @Shogunivar said, you can even delete data in DB with GET, but that would be nonsense. – shaochuancs Mar 14 '17 at 07:47
  • Ok. I am getting this point. But what will be the problem in using POST. Using GET would be the nonsense, but what about POST as it will not display anything on URL and there are no restrictions in using POST?? – Mohit Bansal Mar 14 '17 at 07:49
  • There is no practical problem with POST, but as DELETE is the more precise verb, it is the better choice in most cases. However, there are several special cases, I'll post them in my answer. – shaochuancs Mar 14 '17 at 08:03
  • Okay. Thanks for your suggestion. – Mohit Bansal Mar 14 '17 at 08:11
  • @MohitBansal is your question correctly answered? If yes, maybe you can "accept" my answer? – shaochuancs May 03 '17 at 03:17

1 Answers1

0

The biggest difference between POST and DELETE is "Semantics". In RESTful point of view, verb should be precise for particular HTTP operation. In your case, even GET request can be used to delete something in DB, but that would obviously be nonsense. To delete something in DB, DELETE is certainly the better choice.

However, there are 2 special cases (maybe more) that you have to use POST instead of DELETE:

  1. entity body of DELETE request will be ignored (Is an entity body allowed for an HTTP DELETE request?), which means if you want to delete something with complex request parameter, you'd better use POST. Of course, "delete with complex parameter" is not a good design, but it happens sometimes.
  2. Some client technology does not support DELETE (e.g. Flex only support GET and POST). In that case, POST is the only choice.
Community
  • 1
  • 1
shaochuancs
  • 12,430
  • 3
  • 40
  • 51