Koto.Infrastructure.Http
0.5.0-preview.3
See the version list below for details.
dotnet add package Koto.Infrastructure.Http --version 0.5.0-preview.3
NuGet\Install-Package Koto.Infrastructure.Http -Version 0.5.0-preview.3
<PackageReference Include="Koto.Infrastructure.Http" Version="0.5.0-preview.3" />
<PackageVersion Include="Koto.Infrastructure.Http" Version="0.5.0-preview.3" />
<PackageReference Include="Koto.Infrastructure.Http" />
paket add Koto.Infrastructure.Http --version 0.5.0-preview.3
#r "nuget: Koto.Infrastructure.Http, 0.5.0-preview.3"
#:package Koto.Infrastructure.Http@0.5.0-preview.3
#addin nuget:?package=Koto.Infrastructure.Http&version=0.5.0-preview.3&prerelease
#tool nuget:?package=Koto.Infrastructure.Http&version=0.5.0-preview.3&prerelease
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:
resulton success, each entry oferrorsas aRemoteError(the remotecode,message,fieldanddetails) on failure. Domain codes cross the service boundary intact, soif (result.FirstError.Code == "wallet.account.insufficient-funds")works without parsing JSON by hand. A malformed remote code becomesgeneral.remote.unknown-errorwith the original code indetails.remoteCode. - Any other body: deserialized as
Ton a success status, otherwise mapped throughMapErrorResponse:
| 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 | 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
- Koto.Application (>= 0.5.0-preview.3)
- Koto.Domain (>= 0.5.0-preview.3)
- Microsoft.Extensions.Http.Resilience (>= 10.6.0)
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 |
0.5.0-preview.3 — the compiler keeps a refusal from getting lost (ADR-028): two analyzers ship inside Koto.Domain and reach every project that references a Koto package. KOTO001: a result is discarded (order.Cancel(reason, now); on a line of its own). KOTO002: FirstError is returned as the failure instead of Errors. Both are errors, so existing code may stop building; migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md