Good day! There was another question. There is an asp.net mvc application that works with a certain database (sql server). And there is another application for which you need to give a certain api for working with the first application (by and large with its database). It is assumed that api should be a set of http methods that allow to receive a response in json format. It begs the use of technology ASP.NET Web Api, about which I heard earlier. The problem is this. I know almost nothing about this technology (well, just that it makes it quite easy and convenient to create such api and more "light" compared to wcf). So far, I see a simpler alternative for me in the form of creating an additional controller in my asp.net mvc application with actions that return JsonResult. Well, in general, such a simple implementation of api. The advantage of this approach for me is that in this case you will not have to create a new project and deploy it separately (a trifle but still) and also that in the mvc application data access occurs via orm and in the case of web api you will somehow duplicate this access code in the web api project.

Now the question itself: are there any significant advantages to the web api technology for solving this problem? Or, on the contrary, do the approach with a separate controller and actions returning JsonResult have any significant drawbacks for solving this task? It’s just that I’m wondering if once there is a technology like WebApi, it’s probably a little silly to implement your api using such a handicraft method as simple Json-action games? Please set the right path! thank you in advance!

  • Web API is only an addition to ASP.NET (or, more precisely, an independent part at all). ASP.NET you both used and will use, only the call to the controllers will change and that's all. Just take a look. Make Hello World and everything will become clear. - Walter Nuss

1 answer 1

WEB API is extremely convenient for creating RESTful services, which you just need to create. He has his own nuances, if MVC combines controllers and presentation engines, then Web Api is only controllers that return data (JSON, XML or others - not important) that work with HTTP. You cannot, for example, redirect a user to another page, but you can send an HTTP code corresponding to a redirect. You cannot display an authorization error, but you will send a status code to the client, in which you will display an error 401 and a message to it.

Absolutely no matter how and what you will write the client application - because WebApi is an HTTP standard.

But if you do not take into account such concepts as the type of output data - what is happening in the controller is practically no different from the usual MVC ! So do not worry about the fact that you can not use the ORM .