11

I use always HttpGet or HttpPost even when my action is executing a delete method on the database.

For what should I use then HttpDelete/HttpPut ?

Elisabeth
  • 20,496
  • 52
  • 200
  • 321
  • You really can google it. Answering your question: you can always use post for data changing. There isn't a real need to use Put and Delete. most applications don't use them. – gdoron Jun 04 '12 at 20:51
  • 2
    A word of advice: on a public web where the search spiders can reach - every Get is triggered while Post is not. So if you can send a Get request to manipulate data be careful of how visible the link is. FWIW – LosManos Jun 04 '12 at 20:55
  • http://prideparrot.com/blog/archive/2011/10/using_http_methods_in_rest – VJAI Jun 05 '12 at 02:02

3 Answers3

16

Web browsers only support GET and POST, so if you are building a web site, there is no need for PUT or DELETE. If you are building a RESTful api, though, PUT and DELETE are the way to go if you want your users to be able to put and/or delete stuff.

EDIT: It seems browsers do support DELETE and PUT in their implementations of XMLHttpRequest. Hence you can use them in ajax requests. Html forms, though, do not support them.

Mikael
  • 500
  • 2
  • 15
3

If you build an OData service.

HTTP DELETE - Deletes the entity data that the specified resource represents. A payload is not present in the request or response messages.

HTTP PUT - Replaces existing entity data at the requested resource with new data that is supplied in the payload of the request message. (msdn)

There's a presentation with Scott Hanselman that might be interesting. (I haven't seen it yet.)

There's also a couple of lectures on pluralsight on OData if you have a subscription there.

Carl R
  • 8,104
  • 5
  • 48
  • 80
2

I guess you have understood about the use of DELETE request but PUT is a little different thing.

If I'm creating a new resource in the server and if the URI through which it can be accessed is decided by me then I'll go for PUT. In most of the cases the URI is decided by the server and hence POST go for creation and PUT usually for update.

Final thing is, like GET both DELETE and PUT are idempotent, means how many times the client send the requests serially the state of the server should be changed to same as in the first request.

VJAI
  • 32,167
  • 23
  • 102
  • 164