WeatherAPI.NET 0.1.0-alpha

This is a prerelease version of WeatherAPI.NET.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package WeatherAPI.NET --version 0.1.0-alpha                
NuGet\Install-Package WeatherAPI.NET -Version 0.1.0-alpha                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WeatherAPI.NET" Version="0.1.0-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WeatherAPI.NET --version 0.1.0-alpha                
#r "nuget: WeatherAPI.NET, 0.1.0-alpha"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WeatherAPI.NET as a Cake Addin
#addin nuget:?package=WeatherAPI.NET&version=0.1.0-alpha&prerelease

// Install WeatherAPI.NET as a Cake Tool
#tool nuget:?package=WeatherAPI.NET&version=0.1.0-alpha&prerelease                

WeatherAPI.NET

Unofficial .NET API client for the weather API available at weatherapi.com.


Getting started

API key

You need an API key to be able to authenticate with the API. You can either sign up for, or log in to WeatherAPI to get your API key.

Creating the client

WeatherAPIClient accepts two constructor parameters: your API key, and a custom base URI for the API. A valid API key must be provided, but specifying a base URI is optional.

string apiKey = "your API key";

WeatherAPIClient weatherApiClient = new WeatherAPIClient(apiKey);

Using the API

API routes are separated out into category classes, referred to as operations, within the client. These classes contain all routes associated with the category, as well as overflow methods providing different request configurations.

Where required, or where available, you'll have the option to provide a request object to the method. The type of request object required is determined by the method you are trying to invoke, but all request objects adopt a fluent API style configuration layout, for example:

RequestEntity request = new RequestEntity()
    .WithCityName("Paris")
    .WithLanguage("fr");

Different request objects exist to provide extra configuration for the category of request you're trying to make. For example, you can request air quality data with the realtime routes:

RealtimeRequestEntity request = new RealtimeRequestEntity()
    .WithCityName("Paris")
    .WithLanguage("fr")
    .WithAirQualityData(true);

Features

Sample projects are available for all primary features. Please see the README to get started with the sample projects.


Extending

The client has been designed to make extending the base functionality as easy, and as flexible, as possible. See the extending sample project for a full example.

Custom response entities

Providing custom entities allows you to inject an object type directly into the deserialization process. This means that there's no hassle serializing and deserializing the standard response objects to get what you want.

// Custom astronomy response entity.
public class CustomAstronomyResponseEntity : AstronomyResponseEntity
{
    private readonly string _message = "I'm a message from a custom entity!";

    public void DoSomethingCustom()
    {
        Console.WriteLine(_message);
    }
}

// Your method to request the custom entity.
public async Task GetCustomAstronomyAsync()
{
    CustomAstronomyResponseEntity customAstronomy = await weatherApiClient.Astronomy.GetAstronomyAsync<CustomAstronomyResponseEntity>();
}

Custom operation classes

To build on top of the existing client's request functionality, you can extend operation classes too. Extending operations requires an extended, custom API client.

// Custom API client.
public class CustomWeatherAPIClient : WeatherAPIClient
{
    protected override IAstronomyOperations ConstructAstronomyOperations()
    {
        return new CustomAstronomyOperations(this);
    }

    public CustomWeatherAPIClient(string apiKey)
        : base(apiKey, null)
    {
    }
}

// Custom astronomy operations.
public class CustomAstronomyOperations : AstronomyOperations
{
    // Overflow methods funnel down to the "most advanced" variant.
    // This means that calls to the "lower level" overflow methods will also invoke this custom logic.
    public override async Task<TAstronomyResponseEntity> GetAstronomyAsync<TAstronomyResponseEntity>(RequestEntity request, CancellationToken cancellationToken = default)
    {
        var astronomyResponseEntity = await base.GetAstronomyAsync<TAstronomyResponseEntity>(request, cancellationToken);

        if (astronomyResponseEntity is CustomAstronomyResponseEntity customAstronomyEntity)
            customAstronomyEntity.DoSomethingCustom();

        return astronomyResponseEntity;
    }

    public CustomAstronomyOperations(IApiRequestor apiRequestor)
        : base(apiRequestor)
    {
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on WeatherAPI.NET:

Package Downloads
WeatherAPI.NET.Extensions.NodaTime

NodaTime extensions to the unofficial .NET API client for the weather API available at weatherapi.com.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1-alpha 2,902 4/15/2021
0.1.0-alpha 4,910 4/14/2021