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

I always use HttpGet or HttpPost, even when my action executes the delete method in the database.

Why use HttpDelete / HttpPut?

+7
source share
3 answers

If you create an OData service.

HTTP DELETE - Deletes entity data specified by the specified resource. The payload is missing in the request or response messages.

HTTP PUT . Replaces existing entity data on the requested resource with new data that is provided in the request message payload. ( msdn )

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

There are also several lectures on multiple views in OData, if you have a subscription.

+2
source

Web browsers only support GET and POST, so if you are creating a website, there is no need for PUT or DELETE. If you create a RESTful api, PUT and DELETE is the way to go if you want your users to be able to add and / or delete files.

EDIT: Browsers seem to support DELETE and PUT in their XMLHttpRequest implementations. Therefore, you can use them in ajax requests. However, Html forms do not support them.

+14
source

I think you understand the use of the DELETE query, but PUT is a slightly different thing.

If I create a new resource on the server, and if the URI through which it will be available is decided by me, then I will go to PUT . In most cases, the URI is determined by the server and, therefore, POST is suitable for creation and PUT usually for updating.

The final thing, for example GET , both DELETE and PUT are idempotent, means how many times the client sends requests in turn, the server status must be changed in the same way as in the first request.

+2
source

All Articles