Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net WEB API - What problems could arise if I use POST instead of PUT and DELETE?

I'm just starting to use Web API and though I found it really easy to create the methods and some configurations I needed, now I run into a problem I don't know how to solve.

Some of the applications that will consume my services are very old and don't support DELETE and PUT methods (j2me applications for example)

I have found that it is possible to do some kind of method emulation by passing something like this :

_method=DELETE|PUT 

However, I'm not really sure if Web API will be able to interpret this and besides, I don't have the faintest idea how to do it. For those reasons I'm thinking in just using POST methods to handle updates and deletes. Having said that, what complications can I expect from not using all the standard methods??

As always any help will be GREATLY appreciated

Thanks in advance.

P.D. It it'd be great if anyone knew how to make the a POST with a _method be routed to the DELETE() or PUT()

like image 834
eddy Avatar asked Jun 16 '14 01:06

eddy


People also ask

What is the difference between under posting and over posting in asp net web API?

What is “Under-Posting” and “Over-Posting” in Web API? Ans: “Under-Posting” - When client leaves out some of the properties while binding then it's called under – posting. “Over-Posting” – If the client sends more data than expected in binding then it's called over-posting.

What is get post put Delete in Web API?

The four main HTTP methods (GET, PUT, POST, and DELETE) can be mapped to CRUD operations as follows: GET retrieves the representation of the resource at a specified URI. GET should have no side effects on the server. PUT updates a resource at a specified URI.

What is the use of put method in Web API?

The HTTP PUT method is used to update an existing record in the data source in the RESTful architecture. So let's create an action method in our StudentController to update an existing student record in the database using Entity Framework. The action method that will handle HTTP PUT request must start with a word Put.

How would you implement the post method in Web API application?

Create a Resource (HTTP POST) In this method set base address of Asp.Net Web API and sets the accept header to application/json that tells the server to send data in JSON Format. PostAsJsonAsyn:This method serializes object into JSON format and send POST request to. After that this method return Response object.


2 Answers

This is fairly common and there is even a somewhat standard http header for it. It's called "http method override" and you'll find some good stuff in this question X-HTTP-Method-Override gives NotFound (404) on ASP.NET Web API

like image 69
Robert Levy Avatar answered Nov 11 '22 14:11

Robert Levy


Thanks to Robert Levy I knew how this problem was called. Once I knew what the problem was , I did a little googlig and in this blog I found how to solve it:

http://www.hanselman.com/blog/HTTPPUTOrDELETENotAllowedUseXHTTPMethodOverrideForYourRESTServiceWithASPNETWebAPI.aspx

like image 31
eddy Avatar answered Nov 11 '22 16:11

eddy