ASP.NET WebApi vs MVC? [closed]

With ASP.NET MVC controllers you can expose your data in different formats. AspNetWebAPI is designed explicitly for creating API's but I can easily do that with MVC controllers, is not clear to me in what cases it would be better than traditional MVC controllers. I'm interested in scenarios where the benefits of WebApi are obvious and it would be worthy to add another complexity layer to my applications.

Question: what are the advantages and/or disadvantages of using asp.net WebApi in respect to MVC ?


Solution 1:

WebApi allows to create services that can be exposed over HTTP rather than through a formal service such as WCF or SOAP. Another difference is in the way how WebApi uses Http protocol and makes it truly First class Http citizen.

UPDATE: The ASP.NET Core, Web API has been integrated into MVC project type. The ApiController class is consolidated into the Controller class. More at: https://wildermuth.com/2016/05/10/Writing-API-Controllers-in-ASP-NET-MVC-6

A relevant link of comparison, discussions & tutorials:

enter image description here

Solution 2:

WebAPI spits out OData, so you get all of the advantages of using OData. For example, with WebAPI you get:

  • Query options such as $filter, $top, $orderby, etc.
    • With traditional MVC controllers you need to implement these yourself.
  • Standardization of the format
    • There are OData clients that will understand the underlying format of your RESTful API.