Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What are the major differences between Web API & MVC?

user-image
Question ajoutée par Mohammad Riyazuddin
Date de publication: 2016/05/24
joy anto
par joy anto , Senior Developer , volvo IT

  • Wep Api is used as a REST based web Interface. It can be part of your implementation of MVC pattern(controller).
  • MVC as implemented by Microsoft and available in .net is used to build web applications primarily providing all the benefits of the MVC design pattern like testablity, seperation of concerns(depends on how you write the code), Robustness etc.
  • Web Api is light weight and can be used for mobile clients(its only one of the possibilities)

A better comparison would be WCF vs Web API

A C Handalage
par A C Handalage , Tech Lead/ Project Coordinator , Srila Systems Pvt LTD

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.
  • In the Web API the request performs tracing with the actions depending on the HTTP services but the MVC request performs tracing with the action name.
  • 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.
  • The Web API includes the various features of the MVC, such as routing, model binding but these features are different and are defined in the "System.Web.Http" assembly. And the MVC features are defined in the " System.Web.Mvc" assembly.
  • The Web API helps the creation of RESTful services over the .Net Framework but the MVC does not support.

Santosh Kapse
par Santosh Kapse , Associate Consultant , TATA CONSULTANCY SERVICES

In the WebForms world, ASP.NET MVC would be equivalent to .aspx pages and ASP.NET Web API would be .asmx.

Mohanad Amen
par Mohanad Amen , Senior Web Developer , Sakhr

- ASP.NET MVC is used to create web applications that returns both views and data but ASP.NET Web API is used to create HTTP services that returns only data

- ASP.NET Web API it helps to build services based on RESTFUL concepts so easily.

- ASP.NET Web API is a good choice to create a stand-alone complete RESTFUL service and in normal ASP.NET MVC applications just the MVC controllers itself enough to return both data and views.

- 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

Taleeb Anwar
par Taleeb Anwar , Software Engineer , Computer Science Corporation (CSC)

Web API are REST services. Though web api is developed on the MVC design pattern - they do not have a view.

ASP.NET MVC is the .NET implementation of MVC pattern. They are used to create web applications (while APIs are like services).

ASP.NET MVC return format (eg JSON, XML) are pre defined, while web api returns data after formatting based on incoming request header. This means that based on two different request a single method can return data in JSON or XML (or any other format).

Finally APIs are created to target developers!

Hope this helps in clarifying the difference between Web API and ASP.NET MVC

Ghoniem Ghoniem
par Ghoniem Ghoniem , Development Manager , Comsys

In breif,

Both of them are architecture patterns,

but MVC is taking about separation of concerns within the same component, the model, the view, and the controller.

But, Layered architecture is taking about the relationships beween the components within the overall solution and the flow of instructions from the front end to the backend models.

Mustafa said
par Mustafa said , Team Leader , SoftexLine former Fakk

 

Basically, a Web API controller is an MVC controller, which uses HttpMessageResponse as the base type of its response, instead of ActionResponse. They are the same in most other respects. The main difference between the project types is that the MVC Application project type adds web specific things like default CSS, JavaScript files and other resources needed for a web site, which are not needed for an API.

 

MVC is used for creating web sites. In this case Controllers usually return a View (i.e. HTML response) to browser requests. Web APIs on the other hand are usually made to be consumed by other applications. If you want to allow other applications to access your data / functionality, you can create a Web API to facilitate this access. For example, Facebook has an API in order to allow App developers to access information about users using the App. Web APIs don't have to be for public consumption. You can also create an API to support your own applications.

Mahmoud Inirat
par Mahmoud Inirat , Senior Software Developer , Iconnect Tech - USA Company

The Mvc used to both create web application includes interfaces(UI) and business logic in addition to use the MVC pattern as API. the API is used to view the data only as xml or string, etc... 

Akbar Shaikh
par Akbar Shaikh , SharePoint Developer , Spire Infotech

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. 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. 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. In Web API the request are mapped to the actions based on HTTP verbs but in MVC it is mapped to actions name. 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. 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. 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. Moreover, Web API is light weight architecture and except the web application it can also be used with smart phone apps.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?