Web API is the preferred way of developing REST apis in .NET core
Create a web api template using .NET Core cli command
dotnet new webapi <apiName>
Susbstitute the api name in place of <apiName>
Default template gets created
Web api contains the Controller (which is synonymous with the Controller in MVC pattern). By default a sample WeatherForecastController is created with GET method.
We can observe that the Controller inherits from ControllerBase interface and it has attribute ApiController. Route attribute contains the [controller] placeholder which means the route path container the name of controller i.e. WeatherForecast
Run the Web api using dotnet cli command
dotnet run
Web api is built and run. Api is hosted at http://localhost:5000 and https://localhost:5001
Launch the following URL
http://localhost:5000/WeatherForecast
The Json data from WeatherController is returned.
Web API supports JSON and XML serialization for returning data. The default serialization is JSON.