/OpenWeatherMap.Core

An asynchronous .NET 5.0 library for interacting with OpenWeatherMap (https://openweathermap.org/API)

Primary LanguageC#MIT LicenseMIT

OpenWeatherMap.Core

An asynchronous .NET 5.0 library for interacting with OpenWeatherMap

Supports:

Setup

Using Dependency Injection

Add the following to your service collection:

services.AddOpenWeatherMap("YOUR_ACCESS_KEY");

Then just inject IOpenWeatherMap to use it.

Without Dependency Injection

OpenWeatherMap openWeatherMap = new OpenWeatherMap("YOUR_ACCESS_KEY");

Caching

Caching is built in but disabled by default. To use caching you can specify the amount of time (in seconds) you wish the call to be cached for when initializing OpenWeatherMap. The following example will cache the call for 60 seconds.

new OpenWeatherMap("YOUR_ACCESS_KEY", 60);

Usage

Current Weather

By latitude and longitude

var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>(40.12, 96.66);              

By city name

var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>("london");              

One Call

var oneCallWeatherModel = await openWeatherMap.QueryAsync<OneCallWeatherModel>(40.12, 96.66); 

Specifying Units

var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>(40.12, 96.66, units: Units.Metric);

Specifying Language

var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>(40.12, 96.66, language: Language.Spanish);