Adding a Forecast Class
Learn how to fetch data from OpenWeather One Call API and display it on the page.
We'll cover the following...
We need to add a Forecast
class to capture the results from the OpenWeather One Call API. We will do this by following these steps:
- Return to Visual Studio.
- Right-click the
Models
folder and select the “Add, Class” option from the menu. - Name the new class
OpenWeather
. - Add the following classes:
Press + to interact
public class OpenWeather{public Daily[] Daily { get; set; }}public class Daily{public long Dt { get; set; }public Temp Temp { get; set; }public Weather[] Weather { get; set; }}public class Temp{public double Min { get; set; }public double Max { get; set; }}public class Weather{public string Description { get; set; }public string Icon { get; set; }}
The preceding classes will be used with the OpenWeather One Call API.
Adding a DailyForecast
component
We need a component to display each day’s forecast. We will do this by following these steps:
- Right-click the
Shared
folder and select the “Add, Razor Component” option from the menu. - Name the new component
DailyForecast
.