Skip to content

6. Tutorial Lab

Alainna Carmon edited this page Oct 6, 2026 · 20 revisions

Tutorial / Lab

Lab Objective

Part 1 — Open the Starter Project and Install Open-Meteo API

After downloading the provided starter project and running a build to make sure there are not any errors running the project, open the Package Manager Console. You can do this by navigating to Tools > NuGet Package Manager > Package Manager Console. Insert the following command into the console to install Open-Meteo Weather API:

dotnet add package openmeteo_sdk

Screenshot 2026-10-01 130823

Part 2 — Create the Weather Model

The first step is to create a model that will hold the weather information returned by the Open-Meteo API.

A model is a C# class used to represent and organize data in your application. In this project, the WeatherData model will represent the information we receive from Open-Meteo, such as the latitude, longitude, temperature, humidity, and wind speed.

Step 1 — Create the Models Folder

In Solution Explorer, locate the WeatherTraining project.

  1. Right-click 'WeatherTraining'.
  2. Select Add then click 'New Folder'.
  3. Name the folder 'Models'

Your project should look similar to: [SCREENSHOT]

using System.Text.Json.Serialization;

namespace WeatherTraining.Models;

public class WeatherData
{
    [JsonPropertyName("latitude")]
    public double Latitude { get; set; }

    [JsonPropertyName("longitude")]
    public double Longitude { get; set; }

    [JsonPropertyName("current")]
    public CurrentWeather Current { get; set; } = new();
}

public class CurrentWeather
{
    [JsonPropertyName("temperature_2m")]
    public double Temperature { get; set; }

    [JsonPropertyName("relative_humidity_2m")]
    public double Humidity { get; set; }

    [JsonPropertyName("wind_speed_10m")]
    public double WindSpeed { get; set; }
}

Here is how the code should look in Visual Studio Code: image

Part 3 — Create the Weather Service

[Explanation]

[Code]

[SCREENSHOT]

Part 4 — Build the API Request

[Explanation]

[Code]

[SCREENSHOT]

Part 5 — Send the Request

[Explanation]

[Code]

[SCREENSHOT]

Part 6 — Read the JSON Response

[Explanation]

[Code]

[SCREENSHOT]

Part 7 — Display the Weather

[Explanation]

[Code]

[SCREENSHOT]

Part 8 — Add Another Weather Variable

[Explanation]

[Code]

[SCREENSHOT]

Part 9 — Challenge Activity

[Explanation]

[Code]

[SCREENSHOT]

Lab Completion Checklist

Clone this wiki locally