ASP.NET WebApi vs MVC ?
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 ?
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:
WebAPI spits out OData, so you get all of the advantages of using OData. For example, with WebAPI you get:
Similarities
1) both inherits from ihhtphandler 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 independently can hosted any where without the depending upon views, MVC controller cant support that as it tightly integrated with the views.
链接地址: http://www.djcxy.com/p/20528.html上一篇: mvc 5检查用户角色
下一篇: ASP.NET WebApi与MVC?