Athenex.Whimclean.Api.FastEndpoints 2.0.0

Prefix Reserved
dotnet add package Athenex.Whimclean.Api.FastEndpoints --version 2.0.0
                    
NuGet\Install-Package Athenex.Whimclean.Api.FastEndpoints -Version 2.0.0
                    
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="Athenex.Whimclean.Api.FastEndpoints" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Athenex.Whimclean.Api.FastEndpoints" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Athenex.Whimclean.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 Athenex.Whimclean.Api.FastEndpoints --version 2.0.0
                    
#r "nuget: Athenex.Whimclean.Api.FastEndpoints, 2.0.0"
                    
#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 Athenex.Whimclean.Api.FastEndpoints@2.0.0
                    
#: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=Athenex.Whimclean.Api.FastEndpoints&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Athenex.Whimclean.Api.FastEndpoints&version=2.0.0
                    
Install as a Cake Tool

Athenex.Whimclean.Api.FastEndpoints

ภาษาไทย

FastEndpoints adapter for Athenex.Whimclean.Api.AspNetCore, the primary Whimclean API package. Install it in applications that write their endpoints with FastEndpoints.

The adapter owns only what is specific to FastEndpoints:

  • FastEndpoints registration and endpoint discovery, including discovery of plain FluentValidation validators;
  • the FastEndpoints OpenAPI document;
  • rendering of FastEndpoints validation failures as the shared error body;
  • whole-value binding of ListQueryRequest filters.

Everything else comes from the primary package and behaves identically in both styles: the error body and exception mappings, status-code responses, Result mapping, the ListQueryRequest contract and its validator, current-user resolution, health endpoints, rate limiting and validated options.

Contents

Installation

dotnet add package Athenex.Whimclean.Api.FastEndpoints

The package references Athenex.Whimclean.Api.AspNetCore, FastEndpoints and FastEndpoints.OpenApi.

Quick start

using Athenex.Whimclean.Api.FastEndpoints;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddFastEndpointsApi();

var app = builder.Build();

app.UseAuthentication();   // when authentication is configured
app.UseAuthorization();    // when authorization is configured
app.UseFastEndpointsApi();

app.Run();

With this setup:

  • every endpoint lives under /api/v1;
  • validators are discovered and run before the endpoint, and a failure answers 400 Validation.Failed;
  • every failure, from a thrown exception to an empty 404, answers with the shared error body described in Error responses;
  • repeated filters query values of a ListQueryRequest are bound whole.

Registration reference

Call Applies to What it does
AddFastEndpointsApi(configureOpenApi) IServiceCollection Registers FastEndpoints with IncludeAbstractValidators enabled, the shared error handling from AddApiErrorHandling, and the FastEndpoints OpenAPI document. The optional delegate customizes DocumentOptions.
AddFastEndpointsApi(configureOpenApi, configureDiscovery) IServiceCollection Same, with a hook that adjusts EndpointDiscoveryOptions after the adapter's settings are applied.
UseFastEndpointsApi(routePrefix, configure) IApplicationBuilder UseApiErrorHandling plus UseFastEndpoints with the route prefix (default api/v1), the validation response builder and the filter binding. The optional delegate adjusts the FastEndpoints Config afterwards.

Customizing the pipeline:

app.UseFastEndpointsApi(
    routePrefix: "api/v2",
    configure: options =>
    {
        options.Security.PermissionsClaimType = "permission";
    });

OpenAPI

Configure the FastEndpoints document during registration:

builder.Services.AddFastEndpointsApi(document =>
{
    document.Title = "Orders API";
});

Validation

Discovery

FastEndpoints pairs each request DTO with its validator at startup. The adapter enables IncludeAbstractValidators, so a validator may derive from FastEndpoints' Validator<TRequest> or directly from FluentValidation's AbstractValidator<TRequest>. This is what allows validators derived from the primary package's ListQueryRequestValidator<TRequest> to be discovered.

Because every AbstractValidator<T> descendant in the scanned assemblies is discovered, limit the scan when an assembly contains validators that are not request validators:

builder.Services.AddFastEndpointsApi(
    configureOpenApi: null,
    configureDiscovery: discovery => discovery.Assemblies = [typeof(Program).Assembly]);

A validator that derives from AbstractValidator<TRequest> cannot use FastEndpoints' Resolve<T>(); inject dependencies through the constructor instead.

Validation response

Failures are rendered through the primary package's ValidationHttpMapper, so the body matches a Minimal API exactly:

{
  "code": "Validation.Failed",
  "description": "One or more validation errors occurred.",
  "errors": [
    { "code": "NotEmptyValidator", "description": "'Customer Id' must not be empty.", "field": "customerId" }
  ]
}

List endpoints

Derive the request from the primary package's ListQueryRequest and the validator from ListQueryRequestValidator<TRequest>. FastEndpoints binds the request from the query string, discovers the validator and runs it before the endpoint:

using Athenex.Whimclean.Api.AspNetCore.Queries;
using Athenex.Whimclean.Application.Pagination;
using Athenex.Whimclean.Application.Queries;
using FastEndpoints;

public sealed class ListTenantsRequest : ListQueryRequest;

public sealed class ListTenantsRequestValidator : ListQueryRequestValidator<ListTenantsRequest>
{
    public ListTenantsRequestValidator()
    {
        AllowSortFields("slug", "name", "status");
        AllowEnumFilterField<TenantStatus>("status");
        AllowFilterField("createdAt", FilterOperator.GreaterThanOrEqual, FilterOperator.LessThan);
    }
}

public sealed class ListTenantsEndpoint(ITenantQueries queries)
    : Endpoint<ListTenantsRequest, OffsetPagedResult<TenantResponse>>
{
    public override void Configure() => Get("tenants");

    public override async Task HandleAsync(ListTenantsRequest request, CancellationToken ct) =>
        await Send.OkAsync(await queries.ListAsync(request.ToListQueryOptions(), ct), ct);
}

The query-string parameters, validation rules and allow-list methods are documented in the primary package's List endpoints section.

UseFastEndpointsApi registers ListQueryBinding.KeepListQueryFiltersWhole, which binds each repeated filters value as-is so that a comma-separated in value (status:in:draft,published) stays in one filter. Call it yourself only when configuring UseFastEndpoints directly.

Error responses

Every failure response uses the primary package's body:

{
  "code": "Order.NotFound",
  "description": "The order was not found.",
  "errors": null
}
Condition HTTP Code
CurrentUserRequiredException 401 Authentication.CurrentUserRequired
PersistenceConcurrencyException 409 Persistence.ConcurrentUpdate
FastEndpoints validation failure 400 Validation.Failed
Response ended with 400 and no body 400 Request.Invalid
Response ended with 401 and no body 401 Authentication.Unauthorized
Response ended with 403 and no body 403 Authorization.Forbidden
Response ended with 404 and no body 404 Resource.NotFound
Any other exception 500 Server.UnexpectedError

Unexpected exception details are logged and never returned to the client.

Returning a domain error from an endpoint

using Athenex.Whimclean.Api.AspNetCore.Errors;

var result = await handler.HandleAsync(request, ct);

if (result.IsFailure)
{
    await Send.ResultAsync(result.Error.ToHttpResult());
    return;
}

ErrorType maps to status codes as in the primary package: Validation 400, Unauthorized 401, Forbidden 403, NotFound 404, Conflict 409, Failure 500.

Adding an exception mapping

Register an IApiExceptionMapper; see Adding an exception mapping in the primary package. Mappers are probed in registration order and the first match wins.


Repository and architecture guide: https://github.com/athene-x/Whimclean

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
2.0.0 108 11/17/2026

Thin adapter over Athenex.Whimclean.Api.AspNetCore: discovers validators derived from its ListQueryRequestValidator, renders validation failures through its shared mapper, applies whole-value binding of ListQueryRequest filters in UseFastEndpointsApi, and offers an AddFastEndpointsApi overload with an endpoint discovery hook.