Lyo.Api.Client
1.0.1
dotnet add package Lyo.Api.Client --version 1.0.1
NuGet\Install-Package Lyo.Api.Client -Version 1.0.1
<PackageReference Include="Lyo.Api.Client" Version="1.0.1" />
<PackageVersion Include="Lyo.Api.Client" Version="1.0.1" />
<PackageReference Include="Lyo.Api.Client" />
paket add Lyo.Api.Client --version 1.0.1
#r "nuget: Lyo.Api.Client, 1.0.1"
#:package Lyo.Api.Client@1.0.1
#addin nuget:?package=Lyo.Api.Client&version=1.0.1
#tool nuget:?package=Lyo.Api.Client&version=1.0.1
Lyo.Api.Client
HTTP client tailored for Lyo-shaped minimal APIs: JSON in/out, gzip/brotli/deflate handling, query-string encoding for GET DTOs, file upload helpers, and System.Text.Json parity with server options when you wire them.
Implements IDisposable (ApiClient disposes underlying resources—resolve via IHttpClientFactory so lifetimes stay correct in DI).
Examples
DI registration
services.AddLyoApiClient(
optionsOverride: o => {
o.BaseUrl = "https://api.example.com/";
o.EnableAutoResponseDecompression = true;
o.AcceptEncodings = ["gzip", "br"];
o.RequestCompression = ApiRequestCompressionType.Gzip;
o.RequestCompressionMinBytes = 4 * 1024;
},
httpClientBuilderOverride: b => b.AddStandardResilienceHandler());
Surface (IApiClient)
Serialization
GetSerializerOptions()exposes effectiveJsonSerializerOptions—use the same instance for ad-hoc serializers in your worker to avoid schema drift.
GET
GetAsAsync<TResult>(uri, beforeRequest, ct)basic JSON GET.GetAsAsync<TRequest, TResult>(uri, query, enumerableDelimiter, …)serializesTRequestproperties as query parameters (helps mirrorLyo.Apiendpoints that accept flattened DTO queries).
Bodies & verbs
PostAsAsync/PutAsAsync/PatchAsAsync/DeleteAsAsyncmap to JSON content (generic + non-generic overloads).PostAsBinaryAsyncfor raw byte returns (exports, generated PDFs, etc.).
Files
GetFileAsync/GetFileWithTypeAsyncbuffer entire payload.GetFileStreamAsyncreturnsStream+ filename + length without forcing memory spikes—caller disposes underlyingHttpResponseMessageper XML contract.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.
Throws ApiException wrapping non-success status codes with 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)
Configuration section: ApiClientOptions.SectionName = "ApiClient". Integration-specific clients (Discord, Endato, ESPN, Typecast, …) subclass this type and shadow SectionName
so all transport flags bind under their 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 HttpClientHandler.AutomaticDecompression for gzip/deflate/br when ApiClient creates its own handler. |
RequestCompression |
None |
ApiRequestCompressionType for outgoing JSON bodies: None, Gzip, Deflate, Brotli. Sets Content-Encoding accordingly. |
RequestCompressionMinBytes |
1024 |
Minimum serialized payload size before compression kicks in (avoids spending CPU on tiny bodies). |
Pair request compression with a host that registers AddRequestDecompression (ASP.NET Core 7+) so the server can decode the body.
Compression & performance
- Adds
Accept-Encodingheaders fromAcceptEncodings(duplicates removed, case normalized). - Sets
HttpClientHandler.AutomaticDecompressionwhenEnableAutoResponseDecompressionistrue(mapsgzip/deflate/brwhere the target framework supports Brotli). - Returns the underlying
IHttpClientBuilderso callers can chain resilience, message handlers, or named-client overrides.
DI registration
clientName defaults to 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.
Typical integration tests
Spin WebApplicationFactory for your API host, call through IApiClient, assert ApiException.StatusCode ProblemDetails bodies using shared models from Lyo.Api.Models.
Related
Lyo.Api.Models— payloads + error contracts.Lyo.Api— authoritative server behavior you are mirroring client-side.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Api.Models— (direct, lyo)Lyo.Common— (direct, lyo)Lyo.Diagnostic— (direct, lyo)Lyo.Exceptions— (direct, lyo)Microsoft.Extensions.Http10.0.5— (direct, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5— (direct, microsoft)Lyo.DateAndTime— (transitive, lyo)Lyo.Hashing— (transitive, lyo)Lyo.PackageMetadata— (transitive, lyo)Lyo.Query.Models— (transitive, lyo)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.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 (>= 1.0.1)
- Lyo.Common (>= 1.0.1)
- Lyo.Diagnostic (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Microsoft.Extensions.Http (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
-
net10.0
- Lyo.Api.Models (>= 1.0.1)
- Lyo.Common (>= 1.0.1)
- Lyo.Diagnostic (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Microsoft.Extensions.Http (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
NuGet packages (15)
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.Job.Web.Components
Blazor components library for managing, monitoring, and operating Lyo jobs with MudBlazor integration. |
|
|
Lyo.Endato.Client
Client library for the Endato data enrichment API. Provides person lookup, enrichment, and data querying capabilities. |
|
|
Lyo.Config.Api.Client
HTTP client for the Lyo central Config API (conditional resolve, ETags, DI registration). |
|
|
Lyo.Reporting.Client
HTTP client for the Lyo Reporting API. |
GitHub repositories
This package is not used by any popular GitHub repositories.