Koto.Api.FastEndpoints 0.5.0-preview.7

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

Koto.Api.FastEndpoints

FastEndpoints integration for Koto DDD building blocks. Builds on Koto.Api.AspNetCore (the Envelope<T> response, KotoApiOptions status classifier, EnrichmentGuard).

What's included

Type Purpose
CommandEndpoint<TCommand> Dispatches a void command → Envelope<object?> with result: null
CommandEndpoint<TCommand, TResult> Dispatches a result command → Envelope<TResult>
QueryEndpoint<TQuery, TResult> Dispatches a query → Envelope<TResult>
MappedCommandEndpoint<TRequest, TCommand[, TResult]> Maps an HTTP request DTO to a command via ToCommand — keeps server-derived fields out of the wire contract
MappedQueryEndpoint<TRequest, TQuery, TResult> Maps an HTTP request DTO to a query via ToQuery
UseKotoFastEndpoints() / MapKotoFastEndpoints() UseFastEndpoints with binding and validator failures rendered as the envelope, and parameterless commands/queries allowed as request models
ClaimsPrincipalExtensions.GetUserId() Reads the user id from the NameIdentifier claim (TryGetUserId for the no-throw path)
CorrelationIdMiddleware / ICorrelationIdAccessor Reads/generates X-Correlation-ID, echoes it in the response and in every envelope
GlobalExceptionHandler Unhandled exception → 500 envelope with general.server.internal-error

Every response of a Koto endpoint is the envelope: 200 with success: true on success, the status chosen by KotoApiOptions (404 / 409 / 400 / 422 …) with success: false and all errors on failure. The base classes declare Envelope<TResult> as the FastEndpoints response type, so the generated OpenAPI matches what is sent.

Setup

// Program.cs
builder.Services.AddKotoApi();          // Koto.Api.AspNetCore + correlation id + exception handler
// Or customize the error → status classifier:
builder.Services.AddKotoApi(o => o.Map("payments.gateway.failed", 502));
builder.Services.AddFastEndpoints();
// ... other services

var app = builder.Build();
app.UseKotoApi();                        // correlation id middleware + exception handler
app.UseKotoFastEndpoints();              // instead of UseFastEndpoints(): binding errors in the envelope too
app.Run();

Implementing an endpoint

HandleAsync is sealed on all base endpoints — you only write Configure():

// Void command → 200 { success: true, result: null }
public class DeleteOrderEndpoint : CommandEndpoint<DeleteOrderCommand>
{
    public override void Configure()
    {
        Delete("/orders/{id}");
        AllowAnonymous();
    }
}

// Command with result → 200 { success: true, result: "7c9e…" }
// The result type is what goes to the wire: return the Guid of a new order, not its OrderId.
public class PlaceOrderEndpoint : CommandEndpoint<PlaceOrderCommand, Guid>
{
    public override void Configure() => Post("/orders");
}

// Query → 200 / 404 (*.not-found) with the envelope
public class GetOrderEndpoint : QueryEndpoint<GetOrderQuery, OrderDto>
{
    public override void Configure()
    {
        Get("/orders/{id}");
        AllowAnonymous();
    }
}

Commands and queries without parameters

A command or query with no properties is a valid request model — UseKotoFastEndpoints() / MapKotoFastEndpoints() turn on FastEndpoints' AllowEmptyRequestDtos and drop the default application/json requirement for such endpoints, so a bodyless call works:

public sealed record GetHealthQuery : IQuery<HealthDto>;
public sealed record RebuildIndexCommand : ICommand;

public sealed class RebuildIndexEndpoint : CommandEndpoint<RebuildIndexCommand>
{
    public override void Configure() => Post("/index/rebuild");   // POST with no body → 200 envelope
}

Endpoints whose request has properties are unchanged (a POST still needs Content-Type: application/json). The content-type part is applied through Config.Endpoints.Configurator, which holds a single action: a host that assigns its own configurator replaces Koto's, so call KotoFastEndpointsConfig.ApplyKotoDefaults(ep) from it to keep both.

Server-derived fields (claims, route, tenant)

When a command/query carries fields that must come from the server (the caller's user id, tenant, correlation id) and must not be bindable from the request body, use the mapped endpoints. The request DTO omits those fields; ToCommand/ToQuery builds the command from the request and the endpoint context (User, Route<T>(), headers):

public sealed record SubmitJudgmentRequest(Guid SubmissionId, int GoeScore); // no JudgeId on the wire
public sealed record SubmitJudgmentCommand(Guid JudgeId, Guid SubmissionId, int GoeScore) : ICommand<Judgment>;

public sealed class SubmitJudgmentEndpoint
    : MappedCommandEndpoint<SubmitJudgmentRequest, SubmitJudgmentCommand, Judgment>
{
    public override void Configure() { Post("/api/v1/judgments"); Policies("IsJudge"); }

    protected override SubmitJudgmentCommand ToCommand(SubmitJudgmentRequest r) =>
        new(JudgeId: User.GetUserId(), r.SubmissionId, r.GoeScore); // JudgeId from claims, not the body
}

Prefer the plain CommandEndpoint/QueryEndpoint when the request is the command (no server-derived fields). HandleAsync is sealed on the mapped variants — you only implement Configure and ToCommand/ToQuery.

Binding and validator failures

FastEndpoints' own failures (JSON binding, Validator<TRequest> rules) are sent through the same envelope with status 400: a failure carrying a Koto Error in CustomState (MustBeValueObject) keeps its code, any other rule becomes validation.rule.failed with details.rule. The field is camelCased per path segment (items[0].name), matching the JSON property names.

Error code → HTTP status mapping

Status codes come from KotoApiOptions (Koto.Api.AspNetCore): exact code → custom rules → *.not-found 404 → *.already-* / *.conflict 409 → *.unauthorized 401 → *.forbidden 403 → general.* / validation.* / field-bound 400 → 422 fallback. Customize via AddKotoApi(o => o.Map("payments.gateway.failed", 502)).

Upgrading from 0.4

0.5 replaces app.UseFastEndpoints() with app.UseKotoFastEndpoints(), seals HandleAsync on every base endpoint (SendCommandAsync / SendQueryAsync are gone — endpoints implement Configure() only) and sends every response as the Envelope<T>. 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 54 11/30/2026
0.5.0-preview.8 54 11/30/2026
0.5.0-preview.7 56 11/29/2026
0.5.0-preview.6 53 11/29/2026
0.5.0-preview.5 57 11/29/2026
0.5.0-preview.4 55 11/29/2026
0.5.0-preview.3 50 11/29/2026
0.5.0-preview.2 53 11/29/2026
0.5.0-preview.1 68 11/8/2026
0.4.0 177 7/21/2026
0.3.0-preview.15 91 7/21/2026
0.3.0-preview.14 86 7/21/2026
0.3.0-preview.13 78 7/21/2026
0.3.0-preview.12 78 7/21/2026
0.3.0-preview.11 83 7/21/2026
0.3.0-preview.10 81 7/21/2026
0.3.0-preview.9 90 7/21/2026
0.3.0-preview.8 89 7/21/2026
0.3.0-preview.7 85 7/21/2026
0.3.0-preview.6 85 7/20/2026
Loading failed

0.5.0-preview.7 — IEventSourcedRepository moved to Koto.Application (the application layer no longer references Marten; Layers.ShouldNotReference stopped failing on correct services); DomainMap keeps nullable reference types (Email? instead of Email). Breaking: using Koto.Application for IEventSourcedRepository. Since preview.6: WolverineFx 6.66.1 and Marten 9.64.0 on one Weasel. Migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md