Koto.Infrastructure.Http 0.5.0-preview.4

This is a prerelease version of Koto.Infrastructure.Http.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Koto.Infrastructure.Http --version 0.5.0-preview.4
                    
NuGet\Install-Package Koto.Infrastructure.Http -Version 0.5.0-preview.4
                    
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="Koto.Infrastructure.Http" Version="0.5.0-preview.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Koto.Infrastructure.Http" Version="0.5.0-preview.4" />
                    
Directory.Packages.props
<PackageReference Include="Koto.Infrastructure.Http" />
                    
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 Koto.Infrastructure.Http --version 0.5.0-preview.4
                    
#r "nuget: Koto.Infrastructure.Http, 0.5.0-preview.4"
                    
#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 Koto.Infrastructure.Http@0.5.0-preview.4
                    
#: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=Koto.Infrastructure.Http&version=0.5.0-preview.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Koto.Infrastructure.Http&version=0.5.0-preview.4&prerelease
                    
Install as a Cake Tool

Koto.Infrastructure.Http

Anti-Corruption Layer for synchronous HTTP calls between services. Part of the Koto suite.

Install

dotnet add package Koto.Infrastructure.Http

What's included

Type Purpose
ServiceHttpClient Abstract base for typed HTTP clients; reads Koto envelopes and maps other HTTP errors to Result<T>
RemoteError An error returned by another Koto service (code, message, field, details)
HttpErrors Catalog for non-envelope responses (general.resource.not-found, …)
ICorrelationIdAccessor Interface for providing the current correlation ID
CorrelationIdHandler Delegating handler that propagates X-Correlation-ID
AddServiceHttpClient<TInterface, TImplementation>() Registers with standard resilience (retry + circuit breaker + timeout)

Usage

1 — Define the application interface (no HTTP here)

// Application layer
public interface IPaymentService
{
    Task<Result<PaymentId>> ChargeAsync(Money amount, CancellationToken ct);
}

2 — Implement with the HTTP client

// Infrastructure layer
public class PaymentServiceHttpClient : ServiceHttpClient, IPaymentService
{
    public PaymentServiceHttpClient(HttpClient http) : base(http) { }

    public async Task<Result<PaymentId>> ChargeAsync(Money amount, CancellationToken ct)
    {
        var response = await Http.PostAsJsonAsync("/charges",
            new { Amount = amount.Amount, Currency = amount.Currency }, ct);
        return await ReadResultAsync<PaymentId>(response, ct);
    }

    public async Task<Result> RefundAsync(PaymentId payment, CancellationToken ct)
    {
        var response = await Http.PostAsync($"/charges/{payment.Value}/refund", content: null, ct);
        return await ReadResultAsync(response, ct);   // no value expected: Result.Ok or the remote errors
    }
}

3 — Register

// Implement ICorrelationIdAccessor (typically wraps IHttpContextAccessor):
services.AddScoped<ICorrelationIdAccessor, HttpContextCorrelationIdAccessor>();

services.AddServiceHttpClient<IPaymentService, PaymentServiceHttpClient>(
    name: "payment-service",
    baseUrl: config["Services:Payment:BaseUrl"]!);

Standard resilience pipeline is applied automatically (3 retries with exponential back-off, circuit breaker, 30 s timeout).

Reading responses

ReadResultAsync<T> returns a domain Result<T>, ReadResultAsync a Result for calls that return no value. The calling handler returns them like any other domain result. An empty success body where a value is expected is HttpErrors.ResponseEmpty.

  • A Koto envelope body is unwrapped: result on success, each entry of errors as a RemoteError (the remote code, message, field and details) on failure. Domain codes cross the service boundary intact, so if (result.FirstError.Code == "wallet.account.insufficient-funds") works without parsing JSON by hand. A malformed remote code becomes general.remote.unknown-error with the original code in details.remoteCode.
  • Any other body: deserialized as T on a success status, otherwise mapped through MapErrorResponse:
HTTP status Error
404 HttpErrors.ResourceNotFound — general.resource.not-found
409 HttpErrors.ResourceConflict — general.resource.conflict
400 / 422 HttpErrors.RequestInvalid — general.request.invalid (message = response body)
5xx HttpErrors.ServerUnexpected — general.server.unexpected (details.statusCode)
other HttpErrors.HttpFailure — general.server.http-error

Override MapErrorResponse to add service-specific errors.

Service-to-service auth

// calling side
services.AddServiceHttpClient<IWalletService, WalletClient>(
    "wallet", "http://wallet", o => o.ApiKey = configuration["ServiceAuth:Key"]!);

// receiving side (Koto.Api.AspNetCore)
services.AddAuthentication().AddServiceKey(configuration["ServiceAuth:Key"]!);
// internal endpoint: Roles("Service")

Upgrading from 0.4

0.5 unwraps the Koto envelope of the remote service into RemoteErrors that keep the remote code, and moves the fallback errors for non-envelope responses into HttpErrors with new codes (general.conflict → general.resource.conflict, …). The step-by-step guide for the whole suite, with before/after code, is docs/migrations/0.4-to-0.5.md.

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
0.5.0-preview.9 53 11/30/2026
0.5.0-preview.8 54 11/30/2026
0.5.0-preview.7 54 11/29/2026
0.5.0-preview.6 52 11/29/2026
0.5.0-preview.5 52 11/29/2026
0.5.0-preview.4 51 11/29/2026
0.5.0-preview.3 59 11/29/2026
0.5.0-preview.2 55 11/29/2026
0.5.0-preview.1 65 11/8/2026
0.4.0 159 7/21/2026
0.3.0-preview.15 83 7/21/2026
0.3.0-preview.14 90 7/21/2026
0.3.0-preview.13 86 7/21/2026
0.3.0-preview.12 78 7/21/2026
0.3.0-preview.11 77 7/21/2026
0.3.0-preview.10 84 7/21/2026
0.3.0-preview.9 88 7/21/2026
0.3.0-preview.8 79 7/21/2026
0.3.0-preview.7 87 7/21/2026
0.3.0-preview.6 75 7/20/2026
Loading failed

0.5.0-preview.4 — a value object's factory parses and never answers "required": MustBeValueObject reports a missing value itself (general.value.is-required, bound to the field) and does not call the factory with null. Remove "required" errors from value-object factories. Since preview.3: analyzers KOTO001 (a result is discarded) and KOTO002 (FirstError returned as the failure) are errors. Migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md