Lyo.Api.Client
2.0.0
dotnet add package Lyo.Api.Client --version 2.0.0
NuGet\Install-Package Lyo.Api.Client -Version 2.0.0
<PackageReference Include="Lyo.Api.Client" Version="2.0.0" />
<PackageVersion Include="Lyo.Api.Client" Version="2.0.0" />
<PackageReference Include="Lyo.Api.Client" />
paket add Lyo.Api.Client --version 2.0.0
#r "nuget: Lyo.Api.Client, 2.0.0"
#:package Lyo.Api.Client@2.0.0
#addin nuget:?package=Lyo.Api.Client&version=2.0.0
#tool nuget:?package=Lyo.Api.Client&version=2.0.0
Lyo.Api.Client
Lyo-specific HTTP client on top of LyoHttpClient. Non-success responses throw ApiException with RFC 7807 problem-details when the body parses. QueryProjectAsync / QueryConcreteAsync POST to {route}/QueryProject and {route}/QueryConcrete using Lyo.Query.Models only here.
Vendor clients (Endato, Typecast, ESPN, Discord, Google Maps) now inherit LyoHttpClient in Lyo.Http.Client. Config.Api.Client stays on ApiClient. Resolve via IHttpClientFactory.
Features
IApiClient/ApiClient. Subclass ofLyoHttpClient. JSON verbs inherited;EnsureSuccessAsyncmaps problem-details toApiException. User-Agent isLyo/{version}(no UA rotation).QueryProjectAsync/QueryConcreteAsync.POST {route}/QueryProjectandPOST {route}/QueryConcrete.ApiRouteBuilder.Build(routePrefix, relativePath)applies the host's configured mount point, andWithIncludes(route, includes)appends oneincludequery parameter per navigation to expand.AddLyoApiClient. Factory registration forIApiClientplus optional correlation handler. VendorAddLyoApiClient<T,T>is obsolete — useAddLyoHttpClient.
Examples
Register in DI
services.AddLyoApiClient(
optionsOverride: o => {
o.BaseUrl = "https://api.example.com/";
o.EnableAutoResponseDecompression = true;
o.AcceptEncodings = ["gzip", "br"];
o.RequestCompression = LyoHttpRequestCompressionType.Gzip;
o.RequestCompressionMinBytes = 4 * 1024;
},
httpClientBuilderOverride: b => b.AddStandardResilienceHandler());
Register a vendor client
// Vendor packages call AddLyoHttpClient and return IHttpClientBuilder.
services.AddEndatoClientFromConfiguration(configuration)
.AddStandardResilienceHandler();
IApiClient methods
Serialization
- Effective
JsonSerializerOptionscome fromGetSerializerOptions(). Use the same instance for ad-hoc serializers in your worker to avoid schema drift.
GET
GetAsAsync<TResult>(uri, beforeRequest, ct)returns deserialized JSON.GetAsAsync<TRequest, TResult>(uri, query, enumerableDelimiter, …)serializesTRequestproperties as query parameters so GET DTOs matchLyo.Apiflattened query endpoints.
Bodies and verbs
PostAsAsync/PutAsAsync/PatchAsAsync/DeleteAsAsyncmap to JSON content (generic + non-generic overloads).PostAsBinaryAsyncfor raw byte returns (exports, generated PDFs, etc.).
Files
GetFileAsync/GetFileWithTypeAsyncbuffer the payload as theHttpClientalready decoded it. UseAddLyoApiClient/LyoHttpClientHandlerso gzip/br/deflate transport encoding is stripped. A stored.gzwithoutContent-Encodingis left as-is.GetFileStreamAsyncreturnsStream+ filename + length without forcing memory spikes. Dispose the stream to release the response.PostFileAsAsyncoverloads stream/byte[]/path +FileTypeInfofor MIME + extension hints.
Customization hook
Each method accepts optional Action<HttpRequestMessage> to append auth headers (Authorization: Bearer …), correlation ids, Accept overrides, or tracing headers.
Non-success status codes throw ApiException wrapping contextual payload extraction (see class for available properties). ApiException derives from
Lyo.Exceptions.Models.HttpException, so callers can handle it through the shared HTTP hierarchy: StatusCode and ErrorCode (populated from the first parsed
LyoProblemDetails error code) come from the base type, and IsTransient is true for 408/429/502/503/504, which lets Lyo.Resilience retry pipelines pick it up
automatically.
Options (ApiClientOptions)
Bind from ApiClientOptions.SectionName = "ApiClient". Clients for a specific integration (Discord, Endato, ESPN, Typecast, …) subclass the options type and shadow SectionName
so transport flags land under that integration's own section.
| Property | Default | Description |
|---|---|---|
BaseUrl |
null |
When set, becomes HttpClient.BaseAddress (trailing / enforced); relative URIs resolve against it. |
EnsureStatusCode |
true |
Calls EnsureSuccessStatusCode after each response. Set false when the server returns problem-details bodies on non-success codes that the caller wants to inspect. |
AcceptEncodings |
["gzip","deflate","br"]* |
Sent as Accept-Encoding. *On netstandard2.0 the default drops br (Brotli is not built in there). Duplicates are removed and normalized to lowercase. |
EnableAutoResponseDecompression |
true |
Enables LyoHttpClientHandler.AutomaticDecompression for gzip/deflate/br when the client uses that primary handler (AddLyoApiClient / CreateHttpClient). Replacing the primary handler drops decompression unless the replacement sets it. |
RequestCompression |
None |
LyoHttpRequestCompressionType for outgoing JSON bodies: None, Gzip, Deflate, Brotli. Sets Content-Encoding accordingly. |
RequestCompressionMinBytes |
1024 |
Minimum serialized payload size before compression applies (skips CPU on tiny bodies). |
Request compression only works if the host also registers AddRequestDecompression (ASP.NET Core 7+) and can decode the compressed body.
Compression and performance
- Adds
Accept-Encodingheaders fromAcceptEncodings(duplicates removed, case normalized). - Uses
LyoHttpClientHandleras theIHttpClientFactoryprimary handler (UseLyoHttpClientHandler/UseLyoHttpClientHandler<TOptions>). Other typed clients (Config, etc.) should call the same helper instead of copyingAutomaticDecompressionsetup. - JSON methods still sniff gzip/deflate magic bytes and strip a BOM. File/binary methods do not: they return whatever the handler already decoded.
- A later
ConfigurePrimaryHttpMessageHandlerreplaces decompression. SubclassLyoHttpClientHandleror setAutomaticDecompressionon the replacement. Do not add a second decompressingDelegatingHandler. - Returns the underlying
IHttpClientBuilderso callers can chain resilience, message handlers, or named-client overrides.
Register in DI
The default clientName is nameof(IApiClient) for named HttpClientFactory resolution. Bind from configuration with the standard services.Configure<ApiClientOptions>(config.GetSection(ApiClientOptions.SectionName)) if you prefer the section route.
Vendor client registration (AddLyoApiClient<TClient, TOptions>)
Vendor clients (Endato, Typecast, ESPN Fantasy Football, Discord, Google Maps) inherit LyoHttpClient and register with AddLyoHttpClient<TClient, TOptions>, which returns IHttpClientBuilder.
The obsolete AddLyoApiClient<TClient, TOptions> overloads on this package forward to that factory path so older hosts still compile. Do not use singleton + GetService<HttpClient>().
Typical integration tests
Stand the API up under WebApplicationFactory, talk to it through IApiClient, then assert ApiException.StatusCode and ProblemDetails payloads with types from Lyo.Api.Models.
Related
Lyo.Api.Models. Payloads + error contracts.Lyo.Api. Server endpoints this client calls.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Api.Models(direct, lyo)Lyo.Common.Json(direct, lyo)Lyo.Common.Metadata(direct, lyo)Lyo.Configuration(direct, lyo)Lyo.Diagnostic(direct, lyo)Lyo.Exceptions(direct, lyo)Lyo.Http.Client(direct, lyo)Lyo.Metrics(direct, lyo)Lyo.Query.Models(direct, lyo)Microsoft.Extensions.Http10.0.5(direct, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5(direct, microsoft)Lyo.Common.Core(transitive, lyo)Lyo.DateAndTime(transitive, lyo)Lyo.Hashing(transitive, lyo)Lyo.PackageMetadata(transitive, lyo)Lyo.Parameters(transitive, lyo)Lyo.Result(transitive, lyo)AngleSharp1.5.0(transitive, third-party)Microsoft.Bcl.AsyncInterfaces10.0.5(transitive, microsoft, netstandard2.0)Microsoft.Extensions.Configuration.Binder10.0.5(transitive, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5(transitive, microsoft)System.IO.Hashing10.0.5(transitive, microsoft, net10.0)System.Memory4.6.3(transitive, microsoft, netstandard2.0)System.Text.Json10.0.5(transitive, microsoft, netstandard2.0)System.Threading.RateLimiting10.0.5(transitive, microsoft)System.Threading.Tasks.Extensions4.6.3(transitive, microsoft)
| Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | 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 | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Lyo.Api.Models (>= 2.0.0)
- Lyo.Common.Metadata (>= 2.0.0)
- Lyo.Configuration (>= 2.0.0)
- Lyo.Diagnostic (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Http.Client (>= 2.0.0)
- Lyo.Metrics (>= 2.0.0)
- Lyo.Query.Models (>= 2.0.0)
- Microsoft.Extensions.Http (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
-
net10.0
- Lyo.Api.Models (>= 2.0.0)
- Lyo.Common.Metadata (>= 2.0.0)
- Lyo.Configuration (>= 2.0.0)
- Lyo.Diagnostic (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Http.Client (>= 2.0.0)
- Lyo.Metrics (>= 2.0.0)
- Lyo.Query.Models (>= 2.0.0)
- Microsoft.Extensions.Http (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
NuGet packages (16)
Showing the top 5 NuGet packages that depend on Lyo.Api.Client:
| Package | Downloads |
|---|---|
|
Lyo.Web.Components
Blazor components library for the Lyo web UI framework with MudBlazor integration. |
|
|
Lyo.Config.Api.Client
HTTP client for the Lyo central Config API (conditional resolve, ETags, HTTP IConfigStore over manage routes). |
|
|
Lyo.Job.Client
HTTP client for the Lyo Job API and IMqService-backed job event publisher for scheduler/worker hosts. |
|
|
Lyo.Authentication.Web.Components
Host-agnostic Razor / MudBlazor pages for Lyo authentication: provider login, JWT debug workbench, and user profile (self + other). Pair with `Lyo.Authentication.Web.Components.Server` (BFF cookie flow) or `Lyo.Authentication.Web.Components.Wasm` (direct token flow). |
|
|
Lyo.FileStorage.Web.Components
Reusable Blazor components for file storage: upload/save, path tree browser, DEK/KEK migration and rotation, metadata/expected-storage browser grids. |
GitHub repositories
This package is not used by any popular GitHub repositories.