DiscosWebSdk 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DiscosWebSdk --version 1.0.0
NuGet\Install-Package DiscosWebSdk -Version 1.0.0
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="DiscosWebSdk" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DiscosWebSdk --version 1.0.0
#r "nuget: DiscosWebSdk, 1.0.0"
#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 DiscosWebSdk as a Cake Addin
#addin nuget:?package=DiscosWebSdk&version=1.0.0

// Install DiscosWebSdk as a Cake Tool
#tool nuget:?package=DiscosWebSdk&version=1.0.0

GitHub Workflow Status GitHub top language GitHub Nuget (with prereleases) Nuget

DISCOSweb SDK

This is C# library for interfacing with the European Space Agency's DISCOSweb API.

Installation

You can either use your IDE's package manager, or the Nuget CLI.

dotnet add package DiscosWebSdk

Then add this to your IServiceCollection setup (this could be in startup.cs or program.cs depending on which style of startup you're using).

services.AddDiscosServices(configuration);

Your configuration should contain the following:

{
    "DiscosOptions": {
        "DiscosApiKey": "YourApiKey",
        "DiscosApiUrl": "https://discosweb.esoc.esa.int/api/"
    }
}

Usage

There is a demo app located here.

Models

All models are located in the DISCOSweb_Sdk.Models namespace and inherit from DiscosModelBase.

These models are POCOs as far as is practical and match the data that comes from the API as closely as possible. However, abbreviations have been removed and names adjusted to match standard dotnet formats.

There is a slight quirk where Latitude and Longitude on most Discos models (API side) are presented as strings, which is obviously ridiculous. As such, these are mapped to internal fields and then recast to give us LatitudeDegs and LongitudeDegs fields that are floats.

Each property has a [JsonPropertyName("name")] that indicates how it's serialised by the API. Each enum has an [EnumMember(Value = "")] for the same purpose.

Client

An IDiscosClient interface is provided for sending queries to the API. this only has two methods and should be set up by the DI extentions.

public interface IDiscosClient
{
    public Task<T> GetSingle<T>(string id, string queryString = "");
    public Task<IReadOnlyList<T>> GetMultiple<T>(string queryString = "");
}

.GetSingle<T> queries the API for a single T with a given ID and query string.

.GetMultiple<T> queries the API for multiple Ts with a query string and returns all of them in a list.

It's worth noting that various error situations are handled internally (such as retrying on rate limit violation) and that all results are returned ready-deserialised.

Query Building

A builder has been provided that can be used to construct query strings. This uses a fluent(ish) interface, albeit one without grammar. Most grammar rules are instead enforced through exceptions, but they should be fairly straightforward. An actual fluent interface with grammar is a planned future improvement.

public interface IDiscosQueryBuilder<TObject> where TObject : notnull
{
	public IDiscosQueryBuilder<TObject> AddFilter(FilterDefinition filterDefinition);
	public IDiscosQueryBuilder<TObject> And();
	public IDiscosQueryBuilder<TObject> Or();
	public IDiscosQueryBuilder<TObject> AddInclude(string fieldName);
	public IDiscosQueryBuilder<TObject> AddAllIncludes();
	public IDiscosQueryBuilder<TObject> AddPageSize(int numPages);
	public IDiscosQueryBuilder<TObject> AddPageNum(int  pageNum);
	public IDiscosQueryBuilder<TObject> Reset();
	public string                       Build();
}

The DI container will be set up to be able to provide an IDiscosQueryBuilder<T> for all types inheriting from DiscosModelBase.

Filters

Filters are the most complicated of the parameters that can be built since they can be infinitely combined.

A filter definition is represented by a generic FilterDefinition<TObject, TParam> where TObject is the type of the object being fetched from the API (e.g. Propellant), and TParam is the type of the parameter you'll be querying for (e.g. if you're looking for .Height, TParam is float).

These filters can then be added to the builder using .AddFilter(myFilter).

To combine filters, the .And() and .Or() methods are used. This builds up an expression tree which is then parsed to create the final query string. The tree must be complete when .Build() is called or an exception will be thrown.

For example, given two FilterDefinitions f1 and f2, we could query for f1 and f2 by doing:

builder.AddFilter(f1).And().AddFilter(f2);
Relationships

A JSON API (such as DISCOS) provides links to related objects. For instance, a LaunchVehicle has an Operator. By default, these won't be fetched by the client. In order to include them, they need to be added to the query through one of the two provided methods.

builder.AddInclude(fieldName);
builder.AddAllIncludes();

.AddInclude(fieldName) will include a single linked property (use the C# fieldname, not the discos fieldname - this is what nameof is good for). To include different combinations, daisy chain these calls.

.AddAllIncludes() will add every possible include for a given type.

It should be noted that the JSON API does not support recursive fetching. So you can only fetch one layer of related objecs.

There are plans to add lazy loading of these properties on-fetch but that has not been implemented yet.

Paging

The DISCOS API returns data in pages. These can be manipulated using the .AddPageNum(numPages) and .AddPageSize(size) methods. They do exactly what you'd expect.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.8.8 579 6/4/2023
1.8.7 630 3/15/2023
1.8.6 644 3/15/2023
1.8.5 726 1/16/2023
1.8.4 713 1/6/2023
1.8.3 648 12/24/2022
1.8.2 867 12/1/2022
1.8.1 702 11/30/2022
1.7.10 730 11/30/2022
1.7.9 895 8/29/2022
1.7.8 831 8/29/2022
1.7.7 769 8/22/2022
1.7.6 765 8/21/2022
1.7.5 774 8/21/2022
1.7.4 773 8/21/2022
1.7.3 825 8/21/2022
1.7.2 888 8/10/2022
1.7.1 823 8/9/2022
1.7.0 821 8/8/2022
1.6.0 796 8/7/2022
1.5.1 808 8/7/2022
1.5.0 764 8/7/2022
1.4.3 815 8/7/2022
1.4.2 788 8/7/2022
1.4.1 820 8/7/2022
1.4.0 795 8/7/2022
1.3.9 850 8/7/2022
1.3.8 749 8/2/2022
1.3.7 788 8/2/2022
1.3.6 824 8/1/2022
1.3.5 771 7/31/2022
1.3.4 930 6/22/2022
1.3.3 842 6/22/2022
1.3.2 847 6/22/2022
1.3.1 825 6/21/2022
1.3.0 825 6/21/2022
1.2.0 831 6/19/2022
1.1.1 837 6/17/2022
1.0.0 834 6/17/2022