Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET WebApi vs MVC? [closed]

People also ask

Is Web API better than MVC?

There are many differences between MVC and Web API, including: We can use the MVC for developing the Web application that replies as both data and views but the Web API is used for generating the HTTP services that replies only as data.

Is ASP.NET MVC discontinued?

ASP.NET MVC is no longer in active development. The last version update was in November 2018. Despite this, a lot of projects are using ASP.NET MVC for web solution development. As to JetBrains' research, 42% of software developers were using the framework in 2020.

Is ASP Net Web API and ASP.NET MVC same?

Asp.Net Web API VS Asp.Net MVC Asp.Net MVC is used to create web applications that return both views and data but Asp.Net Web API is used to create full-blown HTTP services with an easy and simple way that returns only data, not view. Web API helps to build REST-ful services over the .

Is MVC architecture still relevant 2021?

The MVC architectural pattern ruled the software world in the past twenty or so years. It is simple: you never mix your data with the display of them.


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


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.

Asp.Net Web API VS Asp.Net MVC enter image description here 1. Asp.Net MVC is used to create web applications that returns both views and data but Asp.Net Web API is used to create full blown HTTP services with easy and simple way that returns only data not view.

2. Web API helps to build REST-ful services over the .NET Framework and it also support content-negotiation(it's about deciding the best response format data that could be acceptable by the client. it could be JSON,XML,ATOM or other formatted data), self hosting which are not in MVC.

3. Web API also takes care of returning data in particular format like JSON,XML or any other based upon the Accept header in the request and you don't worry about that. MVC only return data in JSON format using JsonResult.

4. In Web API the request are mapped to the actions based on HTTP verbs but in MVC it is mapped to actions name.

5. Asp.Net Web API is new framework and part of the core ASP.NET framework. The model binding, filters, routing and others MVC features exist in Web API are different from MVC and exists in the new System.Web.Http assembly. In MVC, these featues exist with in System.Web.Mvc. Hence Web API can also be used with Asp.Net and as a stand alone service layer.

6. You can mix Web API and MVC controller in a single project to handle advanced AJAX requests which may return data in JSON, XML or any others format and building a full blown HTTP service. Typically, this will be called Web API self hosting.

7. When you have mixed MVC and Web API controller and you want to implement the authorization then you have to create two filters one for MVC and another for Web API since boths are different.

8. Moreover, Web API is light weight architecture and except the web application it can also be used with smart phone apps.

Original source is here


At some point you might want to forget ASP.NET MVC all together. If you are a .NET developer but you want to build a Single-Page application (using Angular for instance) you'll want the benefits of a RESTful service (WebAPI) without all of the unnecessary bloat that comes with ASP.NET MVC.


Similarities

  1. both inherits from ihttphandler for the asyncrequest so basically apicontroller or mvc controller both are the wrapper around the web.http

Differences:

  1. MVC controller is very heavy if you could go through its definition you can see how many interfaces and the base code it has used, web API is lighter controller and distinguish request by its passed parameters ( yes we can change it too!)

  2. MVC controller has too many features like it return views, action result, javascript result, etc but in web API has either JSON or XML.

  3. API is for implementing Restful(GET, POST, PUT, DELETE, OPTIONS) services which can be independently hosted anywhere without the depending upon views, MVC controller cant support that as it tightly integrated with the views.