Keel.Endpoints 0.1.0-preview.2

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

Keel.Endpoints

One class per endpoint for ASP.NET Core Minimal APIs. Binding, validation and OpenAPI stay native; authorization is fail-closed; analyzers catch route mistakes at build time.

Status: 0.1 preview. The API may change before 1.0. See the roadmap.

namespace Billing.Invoices.Get;

public sealed record GetInvoice(string InvoiceId);

[Get("invoices/{invoiceId}")]
public sealed class Endpoint(InvoiceStore store)
    : ResultEndpoint<GetInvoice, Results<Ok<InvoiceView>, NotFound>>
{
    public override Task<Results<Ok<InvoiceView>, NotFound>> HandleAsync(GetInvoice request, CancellationToken ct) =>
        Task.FromResult<Results<Ok<InvoiceView>, NotFound>>(
            store.Find(request.InvoiceId) is { } invoice ? TypedResults.Ok(invoice) : TypedResults.NotFound());
}
builder.Services.AddKeelEndpoints();
builder.Services.AddValidation();       // .NET 10 native validation
builder.Services.AddProblemDetails();   // RFC 9457 errors

app.MapKeelEndpoints(typeof(Program).Assembly, "/api").RequireAuthorization();
dotnet add package Keel.Endpoints --prerelease

Why

Minimal APIs are a great runtime and an awkward way to organize a large API. Keel.Endpoints gives each operation a class, so a feature is one folder: its contract, its handler, its tests. Everything else is ASP.NET Core: each endpoint is registered as an ordinary Minimal API handler, so RequestDelegateFactory binds it, .NET 10 validates it, typed results document it, and every RouteHandlerBuilder convention you already know still applies.

Endpoint shapes

Base type For Response
Endpoint<TRequest, TResponse> A request in, a body out 200
Endpoint<TRequest> A command, no body out 204
EndpointWithoutRequest<TResponse> No contract, a body out 200
ResultEndpoint<TRequest, TResult> The handler picks the status with Results<...> As typed
StreamEndpoint<TRequest, TItem> A stream of items JSON array or Server-Sent Events

Binding

GET and DELETE bind the contract from route and query, as [AsParameters] does. POST, PUT and PATCH read it from the JSON body. To combine a route value with a body, bind as parameters and mark the body member:

[BindRequest(RequestBinding.Parameters), ValidatableType]
public sealed record RenameInvoice(string InvoiceId, [property: FromBody] RenameInvoiceBody Body);

Validation (.NET 10)

Call AddValidation() and mark contracts with [ValidatableType]. DataAnnotations run before the handler, and failures return 400 problem details. The .NET 10 generator only discovers types it sees in Map* calls, which is why endpoint-class contracts need the attribute; analyzer KEEL004 tells you when it is missing.

Fail-closed authorization

By default the application refuses to start if an endpoint has neither authorization metadata nor AllowAnonymous. A decision on the route group, on the class ([Authorize], [AllowAnonymous]) or in Configure all count:

public override void Configure(EndpointOptions options) => options.RequireAuthorization("admin");

Turn it off with AddKeelEndpoints(o => o.RequireExplicitAuthorization = false).

Per-endpoint configuration

public override void Configure(EndpointOptions options)
{
    options.Summary("Creates an invoice").Tags("Invoices");
    options.Convention(b => b.RequireRateLimiting("invoices").CacheOutput());
}

Configure runs once at map time on an instance created without its constructor, so it must not read injected state.

Streaming

[Get("invoices/events")]
public sealed class Endpoint : StreamEndpoint<WatchInvoices, InvoiceEvent>
{
    public override void Configure(EndpointOptions options) =>
        (options.StreamFormat, options.EventType) = (StreamFormat.ServerSentEvents, "invoice");

    public override async IAsyncEnumerable<InvoiceEvent> HandleAsync(WatchInvoices request,
        [EnumeratorCancellation] CancellationToken ct) { /* yield return ... */ }
}

Analyzers

Shipped inside the package. See docs/diagnostics.md.

Rule Detects
KEEL001 Two endpoints on the same method and template
KEEL002 A route parameter with no matching contract member
KEEL003 A route parameter on a contract read from the body
KEEL004 A contract with validation rules but no [ValidatableType]

Testing

Keel.Endpoints.Testing calls endpoints by type, so tests cannot drift from routes:

var client = new EndpointClient(factory.CreateClient(), prefix: "/api");
var response = await client.SendAsync<Invoices.Get.Endpoint, InvoiceView>(new GetInvoice("42"));
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

FluentValidation

Prefer FluentValidation over DataAnnotations? Add Keel.Endpoints.FluentValidation: an ordinary endpoint filter that runs each argument's registered IValidator<T> and returns the same 400 problem details.

builder.Services.AddKeelFluentValidation(typeof(Program).Assembly);
app.MapKeelEndpoints(typeof(Program).Assembly, "/api").RequireAuthorization().WithFluentValidation();

See its README.

Roadmap

  • 0.2 Native AOT: a source generator for explicit registration.
  • 0.3 Group configuration per folder, dotnet new templates, code fixes.
  • 0.4 A route and contract manifest with breaking-change checks in CI.
  • 1.0 Public API frozen for two previews, full docs, benchmark within 5% of a hand-written Minimal API.

Building

dotnet build
dotnet run --project tests/Keel.Endpoints.Tests

To try everything locally (sample API, analyzers, the package in your own project) see docs/testing-locally.md.

Without access to nuget.org, add -p:KeelOfflineRoslyn=true to compile the analyzers against the Roslyn assemblies bundled with the .NET SDK.

Acknowledgements

The endpoint-class shape was popularized by FastEndpoints and refined by NativeEndpoints, whose "ordinary ASP.NET Core underneath" idea inspired this project. Keel.Endpoints is an independent implementation and shares no code with either.

License

MIT

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.
  • net10.0

    • No dependencies.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Keel.Endpoints:

Package Downloads
Keel.Endpoints.Testing

Typed HTTP calls to Keel.Endpoints endpoint classes in integration tests: the route, its parameters and the body come from the endpoint itself, not from hand-written URLs.

Keel.Endpoints.FluentValidation

FluentValidation for Keel.Endpoints and any Minimal API: an ordinary endpoint filter that runs the registered IValidator<T> for each argument and returns the same 400 problem details as .NET 10 validation.

Keel.Endpoints.OpenTelemetry

Observability for Keel.Endpoints: tags ASP.NET Core's request spans and http.server.request.duration with the endpoint's operation and feature, counts validation errors per field, and optionally traces and times each handler. Built on System.Diagnostics; works with OpenTelemetry, Application Insights or dotnet-counters.

Keel.Endpoints.Idempotency

Safe retries for POST and PATCH in Keel.Endpoints and any Minimal API: with an Idempotency-Key header, the first response is stored and retries get it back without running the handler again. Per-user keys, 422 on a reused key with another request, 409 while the first is still running. Stores in IDistributedCache (memory or Redis) or your own IIdempotencyStore.

Keel.Endpoints.Versioning

API versioning for Keel.Endpoints on top of Asp.Versioning: a version per folder (Features/V2/...), unique operation names per version, and [ApiVersion] on endpoint classes. Versioned routes, version headers and deprecation stay Asp.Versioning's.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-rc.8 62 11/12/2026
1.0.0-rc.7 102 11/1/2026
1.0.0-rc.6 94 11/1/2026
1.0.0-rc.5 104 10/31/2026
1.0.0-rc.4 101 10/31/2026
1.0.0-rc.3 98 10/31/2026
1.0.0-rc.2 116 10/31/2026
1.0.0-rc.1 110 10/24/2026
1.0.0-preview.6 268 10/23/2026
1.0.0-preview.5 78 10/23/2026
1.0.0-preview.4 73 10/23/2026
1.0.0-preview.3 77 10/23/2026
1.0.0-preview.2 71 10/19/2026
1.0.0-preview.1 74 10/18/2026
0.4.0-preview.1 75 10/18/2026
0.3.0-preview.1 71 10/18/2026
0.2.0-preview.1 67 10/18/2026
0.1.0-preview.4 64 10/18/2026
0.1.0-preview.3 70 10/18/2026
0.1.0-preview.2 103 10/18/2026
Loading failed