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
                    
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="Atya.Http.Client" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Atya.Http.Client" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Atya.Http.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Atya.Http.Client --version 2.0.0
                    
#r "nuget: Atya.Http.Client, 2.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.
#:package Atya.Http.Client@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Atya.Http.Client&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Atya.Http.Client&version=2.0.0
                    
Install as a Cake Tool

Atya.Http.Client

Typed HttpClient helpers that return Atya Result values, understand ProblemDetails failures, and propagate correlation identifiers.

NuGet Version Downloads .NET 10.0 License: MIT

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.

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.ProblemDetailsOptions is removed; use StatusKindOverrides (HTTP status to ErrorKind) instead.
  • Operational failures are results, not exceptions. HttpRequestException becomes transport_failure (Unavailable), a timeout becomes timeout (Timeout), body read errors become transport_failure. Cancellation by the caller's token still throws OperationCanceledException; any other exception propagates. You can remove try/catch around 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 status that disagrees is ignored and logged.
  • Bounded reads. MaxResponseBodyBytes (1 MiB), MaxProblemBodyBytes (64 KiB) and MaxJsonDepth (32) are configurable; oversize bodies fail with body_too_large, truncated or too-deep JSON with malformed_payload, non-JSON success bodies with unexpected_content_type. Error responses with non-JSON, oversized or malformed bodies fall back to http_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 by AddAtyaHttpClient. It reads CorrelationContext.Current (fallback CorrelationIdAccessor), validates the id and never overwrites an existing header or uses Activity baggage. If you construct AtyaHttpClient yourself, compose the handler explicitly.
  • AtyaHttpClient takes an ILogger<AtyaHttpClient>. AddAtyaHttpClient is idempotent.
  • Requires Atya.Foundation.Results 1.2.0 (new ErrorKind values).
Product 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. 
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
2.0.0 177 11/28/2026
1.0.0 284 7/12/2026