Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 424
Elisabeth Avatar asked Jun 04 '12 20:06

Elisabeth


2 Answers

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.

like image 197
Carl R Avatar answered Sep 30 '22 02:09

Carl R


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.

like image 31
Mikael Avatar answered Sep 30 '22 01:09

Mikael