When should I use HttpDelete or HttpPut in an asp.net mvc application

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 ?

asked Jun 4, 2012 at 20:49 21k 55 55 gold badges 207 207 silver badges 325 325 bronze badges

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.

Commented Jun 4, 2012 at 20:51

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

Commented Jun 4, 2012 at 20:55 Commented Jun 5, 2012 at 2:02

3 Answers 3

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.

answered Jun 4, 2012 at 21:37 520 2 2 silver badges 15 15 bronze badges

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.

answered Jun 4, 2012 at 20:58 8,194 5 5 gold badges 50 50 silver badges 83 83 bronze badges

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.

answered Jun 5, 2012 at 2:11 32.6k 23 23 gold badges 105 105 silver badges 166 166 bronze badges

Linked

Related

Hot Network Questions

Subscribe to RSS

Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2024.9.10.15036