Creating Your First API

We can use the dotnet new webapi command to create a new API project and play with a few of the things we've learned about.

dotnet new webapi -n MyFirstApi

This will create a new MyFirstApi directory with a Program.cs file.

We can run the application using the dotnet run command or in VS Code.

dotnet run

We can navigate to https://localhost:5001/weatherforecast and see the default weather forecast.

A couple of small refactors we can make to whet your appetite for the next course:

  • Move the WeatherForecast data getter to its own service, and register it with the dependency injection container.
  • Add a little logging. :)

Let's do 'em together!