Web Application and Web Api Project Types at Core Asp.net

I know that Asp.Net MVC and Asp.Net Web API were combined into one code in Asp.net Core and they inherit from the base class Controller and can return IActionResult implementations. This is a view for MVC or Json for web api.

But when I want to create an Asp.net Core project, it offers two templates (Web Application and Web Api ) , in accordance with what I said above, there are no differences between these controllers, why are there two templates? are there any differences that i don't know about?

+5
source share
2 answers

The web application template will create folders and import the material needed for the web application such as jquery, css, etc. Web api template will create folders and import material for web api. In addition, the controllers created by default will have different implementations, for example, the web application will return the views and the views will be created in the corresponding folder.

So, although they come from the same controllers, each type of project requires different dependencies.

If I were you, I would go and create one for each type and see the difference.

If you want to have both a web application and a web application in one project, use areas . Thus, your site and api will have separate controllers, folders and models. Also, if you want to separate them in the future, it will be easy to do.

+6
source

The difference between the two patterns is

The WebAPI template starts with the Controller class, which allows you to respond to RESTful requests at the / api / Values ​​endpoint.

Web application template will provide you with a project supporting MVC environment with some Razor views, a set CSS base for loading and a jQuery library installed.

If you want to create a project with both MVC and API controllers, I would suggest going with the template of the main ASP.NET web application and adding the necessary dependencies.

+3
source

Source: https://habr.com/ru/post/1261879/


All Articles