Unblocking The Main Thread Solving ANRs and Frozen Frames
Difference between asp.net web api and asp.net mvc
1. S.No ASP.NET Web API
ASP.NET MVC
1
Purpose of ASP.NET MVC:
To create web applications that returns both
views and data.
Purpose of ASP.NET Web API:
To create full blown HTTP services with
easy and simple way that returns only data
not view.
i.e., ASP.NET Web API is focused on
making output of raw data easy.
i.e., ASP.NET MVC is focused on making
output of HTML easy.
In the WebForms world, ASP.NET MVC
In the WebForms world, ASP.NET Web API would be equivalent to .aspx pages.
would be equivalent to .asmx pages.
2
Default Assumption for ASP.NET Web
API:
ASP.NET Web API by default assumes that
primitive type comes from query string and
non-primitive types comes from the form. It
also assumes that we would only want to
read the form body once, without caching,
to have lower memory usage and better
performance.
Default Assumption for ASP.NET MVC:
ASP.NET MVC by default assumes user
submitted data can come from multiple
sources, be it in the query string or in the
form.
3
Whether it is possible to make ASP.NET
Web API output HTML ?
Yes
Whether it is possible to make ASP.NET
MVC output raw data ?
Yes
But, we need to do some additional work as But, we need to do some additional work as
provided below,
provided below,
Making additional classes to handle
text/html during content negotiation in
ASP.NET Web API.
Adding logic to handle OData queries in
ASP.NET MVC.
4
GET AJAX Request in ASP.NET Web
API:
ASP.NET Web API allows GET AJAX
request by default.
GET AJAX Request in ASP.NET MVC:
GET AJAX request is blocked by ASP.NET
MVC's JsonResult by default to prevent
CSRF.
5
Whether RESTful services can be created
with ASP.NET Web API ?
ASP.NET Web API helps the creation of
RESTful services over the .Net Framework.
Whether RESTful services can be created
with ASP.NET MVC ?
With ASP.NET MVC, we cannot able to
create RESTful services.
6
Return format of data:
ASP.NET Web API returns the data in
various formats, such as JSON, XML and
other format based on the accept header of
the request.
Return format of data:
ASP.NET MVC returns the data in the JSON
format by using JSONResult.
7
Request Mapping:
Request Mapping:
In ASP.NET Web API the request are
In ASP.NET MVC the request is mapped to
mapped to the actions based on HTTP verbs. actions name.
8
Where we can see the features such as:
model binding, filters, routing etc., in
Where we can see the features such as:
model binding, filters, routing etc., in
2. ASP.NET Web API ?
System.Web.Http
9
ASP.NET MVC?
System.Web.Mvc
Whether content negotiation and self
hosting features are supported ?
ASP.NET Web API supports content
negotiation, self hosting.
Whether content negotiation and self
hosting features are supported ?
ASP.NET MVC does not support content
negotiation and self hosting features.
Content Negatiotion – It is about deciding
the best response format data that could be
acceptable by the client. it could be
JSON,XML,ATOM or other formatted data
10
How routing is defined in ASP.NET Web
API?
Routing is defined by webapiconfig class
i.e., using MapHttpRoute method.
How routing is defined in ASP.NET MVC?
Routing is defined by routeconfig class i.e.,
using MapRoute method .
Unlike MVC, Routing API here does not
use any reference to MVC .
11
When to use ASP.NET Web API?
Web API is more capable of supporting
many different clients,namely, WPF Client,
iPhone, Android, iPad, Windows Phone 7,
Windows Phone 8, Web Browsers: IE,
Firefox, Chrome etc., then ASP.NET Web
API is likely going to be a better choice.
When to use ASP.NET MVC?
Asp.NET MVC is optimized for having a web
browser as a client.
If our only client is a web browser, then MVC
is likely going to be a better choice.
Note:
1.We 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.
2.When we have mixed MVC and Web API controller and you want to implement the authorization
then we have to create two filters one for MVC and another for Web API since boths are different.
Reference:
http://onlydifferencefaqs.blogspot.in/2014/02/difference-between-aspnet-web-api-and.html