Koto.Api.AspNetCore
0.5.0-preview.6
See the version list below for details.
dotnet add package Koto.Api.AspNetCore --version 0.5.0-preview.6
NuGet\Install-Package Koto.Api.AspNetCore -Version 0.5.0-preview.6
<PackageReference Include="Koto.Api.AspNetCore" Version="0.5.0-preview.6" />
<PackageVersion Include="Koto.Api.AspNetCore" Version="0.5.0-preview.6" />
<PackageReference Include="Koto.Api.AspNetCore" />
paket add Koto.Api.AspNetCore --version 0.5.0-preview.6
#r "nuget: Koto.Api.AspNetCore, 0.5.0-preview.6"
#:package Koto.Api.AspNetCore@0.5.0-preview.6
#addin nuget:?package=Koto.Api.AspNetCore&version=0.5.0-preview.6&prerelease
#tool nuget:?package=Koto.Api.AspNetCore&version=0.5.0-preview.6&prerelease
Koto.Api.AspNetCore
ASP.NET Core integration for Koto results: map a handler's AppResult<T> to the Koto Envelope
response from Minimal APIs, MVC controllers or any other ASP.NET Core host.
Koto.Api.FastEndpoints builds on this package.
What you get
ToHttpResult()/ToHttpResultAsync()—AppResult<T>→IResult(Minimal API)ToActionResult()/ToActionResultAsync()—AppResult<T>→ActionResult<Envelope<T>>(MVC)KotoApiOptions— the coarse error → HTTP status classifier and the guard modeEnrichmentGuard— fails fast (Development) when a handler forgot a fuller typed errorServerError— the error behind every 500 (general.server.internal-error)
Only application results are accepted. A domain Result<T> has no ToHttpResult — it must leave
the handler through ForField / Enrich first (see Koto.Application).
The response
HTTP 200
{ "success": true, "result": { "id": "…" }, "errors": [], "correlationId": "0f3c…", "timestamp": "2026-11-08T02:11:03Z" }
HTTP 422
{ "success": false, "result": null,
"errors": [ { "code": "identity.otp.too-many-attempts", "message": "Too many attempts.",
"field": null, "details": { "retryAfterSeconds": 42 } } ],
"correlationId": "0f3c…", "timestamp": "2026-11-08T02:11:09Z" }
Void commands respond 200 with "result": null. Failures are sent as Envelope<object?> — the same
keys with result: null — so Envelope<T> is the declared schema for the endpoint (.Produces<Envelope<T>>()
in Minimal API, automatic in Koto.Api.FastEndpoints) and OpenAPI documents real properties.
Non-JSON responses (files, streams) stay outside the envelope. timestamp comes from the registered TimeProvider (TimeProvider.System unless you
register another one before AddKotoAspNetCore).
Quick start
builder.Services.AddKotoAspNetCore(); // optional: o => o.Map("payments.gateway.failed", 502)
Minimal API:
app.MapPost("/orders", (CreateOrderCommand cmd, ICqrsDispatcher dispatcher, HttpContext ctx, CancellationToken ct)
=> dispatcher.SendAsync(cmd, ct).ToHttpResultAsync(ctx))
.Produces<Envelope<OrderId>>();
MVC controller:
[HttpPost]
public Task<ActionResult<Envelope<OrderId>>> Create(CreateOrderCommand cmd, CancellationToken ct)
=> _dispatcher.SendAsync(cmd, ct).ToActionResultAsync(this);
Status codes — a class for infrastructure, not a second error code
Clients react to errors[].code; the status exists for the machinery that never reads the body
(401 refresh flows, retries on 5xx, alerting, caches). So the mapping is coarse:
| Rule (in order) | Status |
|---|---|
exact code from Map(code, status) |
as configured |
custom rules from Map(error => status?) |
as configured |
*.not-found |
404 |
*.already-*, *.conflict |
409 |
*.unauthorized |
401 |
*.forbidden |
403 |
general.*, validation.*, error bound to a field |
400 |
| everything else | 422 (FallbackStatusCode) |
A failed result is a rule violation the client can act on — never 500. For several errors the
first one decides, and Result.Combine keeps the order you wrote. Customize:
builder.Services.AddKotoAspNetCore(o => o
.Map("payments.gateway.failed", StatusCodes.Status502BadGateway)
.Map(e => e.Code.EndsWith(".rate-limited") ? StatusCodes.Status429TooManyRequests : null));
Rules receive the EnrichedError wrapper; match on the original type through Inner:
o.Map(e => e is EnrichedError { Inner: QuotaExceeded } ? 429 : null).
EnrichmentGuard — the second level of the error contract
The compiler guarantees the data of the error record a handler constructs. The guard checks, at the
API boundary, that the handler did not forget the fuller type: when the scanned assemblies
(AddKotoApplication) contain a record deriving from EnrichedError whose constructor takes an
error of type X — MeetupFullWithAlternative(MeetupFull Cause, Guid AlternativeMeetupId) — a bare
MeetupFull reaching the response is a violation.
| Environment | Default |
|---|---|
| Development | throw InvalidOperationException |
anything else, including hosts without IHostEnvironment |
log a warning, send the response as is |
Override with o.EnrichmentGuard = EnrichmentGuardMode.Off / Warn / Throw.
Upgrading from 0.4
0.5 replaces Problem Details with the Envelope<T> (void commands answer 200, not 204), renames KotoHttpErrorOptions to KotoApiOptions (MapSuffix / MapPrefix → Map(rule)), accepts only AppResult<T> in ToHttpResult / ToActionResult, and deletes KotoProblemDetails. 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.6)
- Koto.Domain (>= 0.5.0-preview.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Koto.Api.AspNetCore:
| Package | Downloads |
|---|---|
|
Koto.Api.FastEndpoints
FastEndpoints integration for Koto: CQRS base endpoints responding with the Koto Envelope, binding errors in the same envelope, correlation ID middleware, and global exception handler. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.5.0-preview.9 | 47 | 11/30/2026 |
| 0.5.0-preview.8 | 58 | 11/30/2026 |
| 0.5.0-preview.7 | 56 | 11/29/2026 |
| 0.5.0-preview.6 | 49 | 11/29/2026 |
| 0.5.0-preview.5 | 54 | 11/29/2026 |
| 0.5.0-preview.4 | 54 | 11/29/2026 |
| 0.5.0-preview.3 | 57 | 11/29/2026 |
| 0.5.0-preview.2 | 54 | 11/29/2026 |
| 0.5.0-preview.1 | 65 | 11/8/2026 |
| 0.4.0 | 197 | 7/21/2026 |
| 0.3.0-preview.15 | 99 | 7/21/2026 |
| 0.3.0-preview.14 | 90 | 7/21/2026 |
| 0.3.0-preview.13 | 79 | 7/21/2026 |
| 0.3.0-preview.12 | 85 | 7/21/2026 |
| 0.3.0-preview.11 | 86 | 7/21/2026 |
| 0.3.0-preview.10 | 94 | 7/21/2026 |
| 0.3.0-preview.9 | 96 | 7/21/2026 |
| 0.3.0-preview.8 | 100 | 7/21/2026 |
| 0.3.0-preview.7 | 89 | 7/21/2026 |
| 0.3.0-preview.6 | 83 | 7/20/2026 |
0.5.0-preview.6 — bug fix: a service with Marten and the Wolverine outbox did not start (Marten and WolverineFx were built on different major versions of Weasel). Now WolverineFx 6.66.1 and Marten 9.64.0; WolverineFx.RuntimeCompilation comes with Koto. A Wolverine handler taking IRepository and IUnitOfWork works and they share one DbContext. ContractJson() is a new instance per endpoint. Breaking: services referencing WolverineFx move to 6.x. Migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md