T
T
Tsiren Naimanov2015-10-04 17:29:07
ASP.NET
Tsiren Naimanov, 2015-10-04 17:29:07

How is ASP.NET MVC development different from ASP.NET API development?

How is ASP.NET MVC development different from ASP.NET API development?
it is the same accepting "methods" on views, with accepting variables? which give back the application/json/xml page?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2015-11-08
@ImmortalCAT

First of all, you need to look at inheritance, how they work:
If you pay attention, webapi and asp.mvc (hereinafter simply mvc) controllers are inherited from different Http.ApiController and Mvc.Controller classes.
You need to understand that webapi is designed to implement REST services covering all types of http requests (GET, PUT, POST, DELETE, etc.) and in response to requests to webapi you get json with an explicit indication of the response status .
In MVC, you can implement the same thing as in webapi, BUT! I personally think that these things need to be clearly distinguished, since in cases with MVC, you must understand that the result of the request in most cases is a generated view, that is, the result of an http request in most cases is html or something similar. Yes, structured json can also be returned to mvc (for example, if you make a table with pagination or dynamic data loading, in this case your Index method returns a view on which you write ajax requests to the GetPageForTable method of the same controller, but there is also a variation, you are free to decide in the GetPageForTable method whether to return only the data or an already generated view).
As a result: webapi is a rest service with all types of http requests, in which the response (by default) comes in a structured json and with an explicit state status (200, 404, etc...) . Well suited for projects where the client can be not only the web, but also a mobile application or something else.
MVC - works like webapi but the result can be generated html markup. In such cases, it is already impossible to support many platforms from the client side, imagine what a mobile application should do with html markup...

V
Vladimir Korotenko, 2015-10-04
@firedragon

return of the result.
In the first case you get html by default, in the second json or xml.

A
Aram Aramyan, 2015-10-05
@GreenBee

In MVC 6 WEBAPI is already built in. So there are no fundamental differences.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question