Atya.Http.Client
2.0.0
Prefix Reserved
dotnet add package Atya.Http.Client --version 2.0.0
NuGet\Install-Package Atya.Http.Client -Version 2.0.0
<PackageReference Include="Atya.Http.Client" Version="2.0.0" />
<PackageVersion Include="Atya.Http.Client" Version="2.0.0" />
<PackageReference Include="Atya.Http.Client" />
paket add Atya.Http.Client --version 2.0.0
#r "nuget: Atya.Http.Client, 2.0.0"
#:package Atya.Http.Client@2.0.0
#addin nuget:?package=Atya.Http.Client&version=2.0.0
#tool nuget:?package=Atya.Http.Client&version=2.0.0
Atya.Http.Client
Typed HttpClient helpers that return Atya Result values, understand ProblemDetails failures, and propagate correlation identifiers.
Overview
Atya.Http.Client wraps HttpClient calls in Result and Result<T> so callers handle expected upstream failures without exception control flow. It reads RFC ProblemDetails responses, aligns status-to-error-kind behavior with Atya.Errors.ProblemDetails, and forwards correlation identifiers on outbound requests.
Installation
dotnet add package Atya.Http.Client
Quick Start
using Atya.Http.Client;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddAtyaHttpClient(options =>
{
options.CorrelationIdAccessor = () => "current-correlation-id";
});
using var provider = services.BuildServiceProvider();
var client = provider.GetRequiredService<AtyaHttpClient>();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.test/customers/42");
var result = await client.SendJsonAsync<CustomerDto>(request);
if (result.IsSuccess)
{
Console.WriteLine(result.Value.Name);
}
else
{
Console.WriteLine(result.Error.Code);
}
public sealed record CustomerDto(string Name);
Feature Tour
Command-style calls
Use SendAsync when the response body is not part of the success contract:
using var request = new HttpRequestMessage(HttpMethod.Delete, "https://api.example.test/customers/42");
var result = await client.SendAsync(request);
JSON calls
Use SendJsonAsync<TValue> when a successful response contains JSON:
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.test/customers/42");
var result = await client.SendJsonAsync<CustomerDto>(request);
Correlation
AtyaHttpClientOptions.CorrelationIdAccessor provides the current correlation id. The client forwards it through X-Correlation-ID unless the request already has that header.
Error Codes
| Code | Meaning |
|---|---|
atya.http.client.http_failure |
The upstream response was not successful and did not provide a specific Atya error code in ProblemDetails. |
atya.http.client.empty_json_response |
The upstream response succeeded but the JSON body deserialized to null. |
When an upstream ProblemDetails payload contains the errorCode extension from Atya.Errors.ProblemDetails, that code is returned instead of atya.http.client.http_failure.
Why This Dependency
Atya.Foundation.Results provides the Result and Error model. Atya.Errors.ProblemDetails owns the ProblemDetails extension names and error-kind mapping options consumed when interpreting upstream HTTP failures. Microsoft.Extensions.Http provides the standard typed-client registration surface.
Links
- Repository: https://github.com/AtyaLibraries/Client
- NuGet: https://www.nuget.org/packages/Atya.Http.Client
- License: https://github.com/AtyaLibraries/Client/blob/development/LICENSE
Migration from 1.x (2.0.0)
- No ASP.NET Core and no ProblemDetails package. The client parses RFC 9457 bodies with its own internal type, so workers,
MAUI and Blazor WebAssembly no longer inherit
Microsoft.AspNetCore.App.AtyaHttpClientOptions.ProblemDetailsOptionsis removed; useStatusKindOverrides(HTTP status toErrorKind) instead. - Operational failures are results, not exceptions.
HttpRequestExceptionbecomestransport_failure(Unavailable), a timeout becomestimeout(Timeout), body read errors becometransport_failure. Cancellation by the caller's token still throwsOperationCanceledException; any other exception propagates. You can removetry/catcharound client calls. - Transport status wins. The error kind comes from the HTTP status (400 Validation, 401, 403, 404, 408/504 Timeout, 409,
429 TooManyRequests, 503 Unavailable, other 5xx Unexpected, other 4xx Failure). A body
statusthat disagrees is ignored and logged. - Bounded reads.
MaxResponseBodyBytes(1 MiB),MaxProblemBodyBytes(64 KiB) andMaxJsonDepth(32) are configurable; oversize bodies fail withbody_too_large, truncated or too-deep JSON withmalformed_payload, non-JSON success bodies withunexpected_content_type. Error responses with non-JSON, oversized or malformed bodies fall back tohttp_failure. - Targets (
Error.Target) contain scheme, host, port and path only; never query string, user info or fragment (ErrorTarget). - Correlation is added by
CorrelationPropagationHandler, registered byAddAtyaHttpClient. It readsCorrelationContext.Current(fallbackCorrelationIdAccessor), validates the id and never overwrites an existing header or uses Activity baggage. If you constructAtyaHttpClientyourself, compose the handler explicitly. AtyaHttpClienttakes anILogger<AtyaHttpClient>.AddAtyaHttpClientis idempotent.- Requires
Atya.Foundation.Results1.2.0 (newErrorKindvalues).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- Atya.Diagnostics.Tracing (>= 1.2.0)
- Atya.Foundation.Guards (>= 1.1.0)
- Atya.Foundation.Results (>= 1.2.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Http (>= 10.0.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.