Keel.Endpoints.Testing 0.1.0-preview.4

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

OpenAPI

The sample shows the full setup: AddOpenApi(), MapOpenApi() and a Scalar API reference (MapScalarApiReference()), with the API key header declared. Run it and the browser opens /scalar.

Endpoints describe themselves through ASP.NET Core's own metadata, so AddOpenApi() / MapOpenApi() (or Swashbuckle, NSwag, Scalar) document routes, parameters, bodies and every typed result. Keel adds two things the shared handler would otherwise get wrong or leave out:

  • Tags from the namespace. Billing.Invoices.Get.Endpoint is tagged Invoices. A tag declared with [Tags], options.Tags(...) or on the group wins. Turn it off with KeelOptions.TagFromNamespace = false.
  • The validation 400. Contracts validated by .NET 10 ([ValidatableType] with AddValidation()) and endpoints validated by WithFluentValidation() document their 400 validation problem response.

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.

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
1.0.0-rc.8 42 11/12/2026
1.0.0-rc.7 64 11/1/2026
1.0.0-rc.6 66 11/1/2026
1.0.0-rc.5 64 10/31/2026
1.0.0-rc.4 65 10/31/2026
1.0.0-rc.3 65 10/31/2026
1.0.0-rc.2 66 10/31/2026
1.0.0-rc.1 68 10/24/2026
1.0.0-preview.6 170 10/23/2026
1.0.0-preview.5 58 10/23/2026
1.0.0-preview.4 62 10/23/2026
1.0.0-preview.3 63 10/23/2026
1.0.0-preview.2 58 10/19/2026
1.0.0-preview.1 64 10/18/2026
0.4.0-preview.1 59 10/18/2026
0.3.0-preview.1 62 10/18/2026
0.2.0-preview.1 64 10/18/2026
0.1.0-preview.4 56 10/18/2026
0.1.0-preview.3 60 10/18/2026
0.1.0-preview.2 59 10/18/2026
Loading failed