Skip to content

About

Weather API and CLI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

WeatherApp

WeatherApp is a .NET 9.0 project that includes a CLI tool and a Web API for fetching weather data.

Requirements

Auth

This project requires an OpenWeather Free API key for calls to the geolocation and weather services.

https://home.openweathermap.org/users/sign_up

Setting environment variable

The environment variable 'OPENWEATHER_API_KEY' must be set.

  • For vscode debugging and running via dotnet command, it can be set in src/WeatherApp.Api/Properties/launchSettings.json
  • For docker, it can be passed with the run command by replacing <REPLACE_ME>
docker run -e OPENWEATHER_API_KEY=<REPLACE_ME> -p 5000:5000 --rm weatherapp:latest

Build Instructions

Build C# Project

From the repo root:

dotnet build

Build Docker Image

docker build -t weatherapp:latest .

Publish Instructions

Publish the Web API or CLI app for deployment:

dotnet publish -c Release

Running Tests

dotnet test

Running the Web API

By default, the API runs on port 5000:

dotnet run --project src/WeatherApp.Api

Or, if published:

dotnet src/WeatherApp.Api/bin/Release/net9.0/WeatherApp.Api.dll

Launching Docker Container

Run the container and expose port 5000:

docker run -e OPENWEATHER_API_KEY=<REPLACE_ME> --rm -p 5000:5000 weatherapp:latest
  • ensure you replace <REPLACE_ME> with your OPENWEATHER_API_KEY.
  • --rm ensures the container is removed when stopped.
  • Port 5000 on host maps to port 5000 in container.

Accessing the Swagger Documentation

Once the Web API is running, open: http://localhost:5000/swagger

WeatherApp CLI

Note, WeatherApp.Api must be running as the CLI makes requests to the WeatherApp.Api.

Description:
  WeatherApp CLI tool for fetching weather data

Usage:
  WeatherApp.Cli [command] [options]

Options:
  -?, -h, --help  Show help and usage information
  --version       Show version information

Commands:
  get-current-weather <zipcode> <Celsius|Fahrenheit>         Get current weather for a zip code
  get-average-weather <zipcode> <Celsius|Fahrenheit> <days>  Get average weather for a zip code over a 2-5 day period

Examples

WeatherApp.Cli get-current-weather 01440 Fahrenheit --output JSON
WeatherApp.Cli get-average-weather 01440 Celsius 3 --output TEXT

TODO

  1. CLI validation
  2. CLI error handling
  3. Enable OAuth
  4. Add additional unit tests
  5. Add end to end integration tests
  6. Shared secret store for API key
  7. Use code formatter

Data Source

This project uses weather data provided by OpenWeather. Data is fetched via the OpenWeather Free API. All weather data is © OpenWeather.

About

Weather API and CLI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages