DiscosWebSdk 1.0.0
See the version list below for details.
dotnet add package DiscosWebSdk --version 1.0.0
NuGet\Install-Package DiscosWebSdk -Version 1.0.0
<PackageReference Include="DiscosWebSdk" Version="1.0.0" />
paket add DiscosWebSdk --version 1.0.0
#r "nuget: DiscosWebSdk, 1.0.0"
// 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
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 T
s 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 FilterDefinition
s 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 | Versions 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. |
-
net6.0
- EnumExtensions.System.Text.Json (>= 1.1.0)
- Hughesjs.Hypermedia.Core (>= 3.1.2)
- Hughesjs.Hypermedia.JsonApi.Client (>= 3.1.2)
- JetBrains.Annotations (>= 2022.1.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
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 | 645 | 6/4/2023 |
1.8.7 | 684 | 3/15/2023 |
1.8.6 | 693 | 3/15/2023 |
1.8.5 | 811 | 1/16/2023 |
1.8.4 | 764 | 1/6/2023 |
1.8.3 | 705 | 12/24/2022 |
1.8.2 | 963 | 12/1/2022 |
1.8.1 | 766 | 11/30/2022 |
1.7.10 | 791 | 11/30/2022 |
1.7.9 | 956 | 8/29/2022 |
1.7.8 | 889 | 8/29/2022 |
1.7.7 | 826 | 8/22/2022 |
1.7.6 | 830 | 8/21/2022 |
1.7.5 | 826 | 8/21/2022 |
1.7.4 | 834 | 8/21/2022 |
1.7.3 | 877 | 8/21/2022 |
1.7.2 | 952 | 8/10/2022 |
1.7.1 | 876 | 8/9/2022 |
1.7.0 | 880 | 8/8/2022 |
1.6.0 | 853 | 8/7/2022 |
1.5.1 | 868 | 8/7/2022 |
1.5.0 | 826 | 8/7/2022 |
1.4.3 | 868 | 8/7/2022 |
1.4.2 | 843 | 8/7/2022 |
1.4.1 | 864 | 8/7/2022 |
1.4.0 | 855 | 8/7/2022 |
1.3.9 | 909 | 8/7/2022 |
1.3.8 | 808 | 8/2/2022 |
1.3.7 | 835 | 8/2/2022 |
1.3.6 | 867 | 8/1/2022 |
1.3.5 | 835 | 7/31/2022 |
1.3.4 | 984 | 6/22/2022 |
1.3.3 | 890 | 6/22/2022 |
1.3.2 | 911 | 6/22/2022 |
1.3.1 | 877 | 6/21/2022 |
1.3.0 | 887 | 6/21/2022 |
1.2.0 | 882 | 6/19/2022 |
1.1.1 | 883 | 6/17/2022 |
1.0.0 | 887 | 6/17/2022 |