I was told to design an API for a client to manipulate some data. Now, trying to keep up with the Jones', I've designed this using WebAPI. I post to my Restful Webservice an object via $.Ajax
Why is this any different from using the same $.Ajax to post to a standard MVC 4.0 Controller?
What are the advantages?
Thanks
====
With regard to potential answer:
Note If you have worked with ASP.NET MVC, then you are already familiar with controllers. They work similarly in Web API, but controllers in Web API derive from the ApiController class instead of Controller class. The first major difference you will notice is that actions on Web API controllers do not return views, they return data.
====
Wouldn't this still be redundant, after all you can always
return JSON(x);
from any MVC controller.
MVC is about how the inner side of your app works. REST is about how your app "talks" with other apps. You can combine them.
The Web API returns the data in various formats, such as JSON, XML and other format based on the accept header of the request. But the MVC returns the data in the JSON format by using JSONResult. The Web API supports content negotiation, self hosting. All these are not supported by the MVC.
1) Web API vs REST API: ProtocolWeb API supports protocol for HTTP/s protocol and URL requests/responses headers that enable services to reach various clients through the web. On the other hand, all communication in the REST API is supported only through HTTP protocol.
Differences between MVC (Model, View, Controller) and ASP.NET Web API are: MVC is for developing applications that return both data and views, while Web API only returns data using the HTTP services. They trace actions differently. Web API traces based on the HTTP service and MVC traces based on the action name.
http://encosia.com/asp-net-web-api-vs-asp-net-mvc-apis/
ASP.NET Web API vs. ASP.NET MVC “APIs” by Dave Ward --Thanks Ant P
A beautiful synopsis:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With