I know that Asp.Net MVC
and Asp.Net Web API
were merged into one code in Asp.net Core
and they inherit from Controller
base class and can all return implementations of IActionResult
. it be a View for MVC or Json for web api.
But when i want to create a Asp.net Core
project, it offers two templates (Web Application and Web Api )
, according to what i said in above, there is no differences between these controllers, why there is two templates? is there any differences that i don't know about it?
API is an interface that exposes an application's data to outside software, whereas web applications are one type of API with stricter requirements. These requirements include network communication, SOAP as the primary protocol, and less accessibility for the public.
In ASP.NET Core, there's no longer any distinction between MVC and Web APIs. There's only ASP.NET MVC, which includes support for view-based scenarios, API endpoints, and Razor Pages (and other variations like health checks and SignalR). In addition to being consistent and unified within ASP.NET Core, APIs built in .
Asp.Net MVC is used to create web applications that return both views and data but Asp.Net Web API is used to create full-blown HTTP services with an easy and simple way that returns only data, not view. Web API helps to build REST-ful services over the .
ASP.NET Core supports creating web APIs using controllers or using minimal APIs. Controllers in a web API are classes that derive from ControllerBase. This article shows how to use controllers for handling web API requests.
The web application template will create folders and import stuff needed for a web application such as jquery, css etc. Web api template will create folders and import stuff for a web api. Also the controllers created by default will have different implementations, for example, web application will be returning views and the views will be created in the appropriate folder.
So although they derive from the same controllers, each type of project requires different dependencies.
If I were you I would go ahead and create one for each type and see the difference.
If you want to have both web api and web application in the same project, use areas. This way your web 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 so.
The difference between 2 templates is-
The WebAPI template starts with a Controller class that will allow you to respond to RESTful requests at the /api/Values endpoint.
The Web Application template will give you an MVC framework enabled project with some Razor views, the bootstrap CSS framework and jQuery library installed.
If you want to create project with both MVC and API controllers then I would suggest to go with ASP.NET Core Web Application template and add require dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With