Fluent.Unions.AspNetCore 1.1.0

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

Fluent.Unions

Fluent.Unions.AspNetCore

NuGet Downloads Publish Documentation

Turns Result, Result<T> and Option<T> into HTTP responses, so an endpoint returns the outcome of an operation and the status code follows from it. It builds on Fluent.Unions.

Installation

dotnet add package Fluent.Unions.AspNetCore

Usage

Convert a result in the handler with ToHttpResult. A value gives 200, a succeeded Result gives 204, None gives 404, and an error gives ProblemDetails. Validation errors give 400 with a ValidationProblemDetails grouped by property.

using Fluent.Unions.AspNetCore;

app.MapGet("/orders/{id}", async (Guid id, IOrders orders) => await orders.LoadOrderAsync(id).ToHttpResult());
app.MapDelete("/orders/{id}", (Guid id, IOrders orders) => orders.CancelAsync(id).ToHttpResult());

Let handlers return results directly. WithResultMapping works on one endpoint or a whole route group, and publishes the value type and the error responses to OpenAPI.

var group = app.MapGroup("/v2/orders").WithResultMapping();

group.MapGet("/{id}", (Guid id, IOrders orders) => orders.LoadOrderAsync(id)); // Task<Result<Order>>

With your own result type

WithResultMapping handles any result type, also one declared with [FluentResult<TError>]: a value gives 200, a succeeded value-less result gives 204, and an error gives the configured error mapping. The OpenAPI metadata has the same shape.

group.MapGet("/customers/{id}", (Guid id) => GetCustomer(id)); // Shop.Result<Customer>

ToHttpResult() also accepts IResult<TSelf, T, TError> when TError : Exception, and maps like the default type. ToHttpResult(onError) works for any error type. There are no Task overloads for your own type, so await first. See your own result type.

By default ValidationError and ValidationErrors give 400, KeyNotFoundException 404, UnauthorizedAccessException 403 and TimeoutException 504. Everything else gives 500 and is logged at Error level. Only validation errors show their messages to the client, also when a ValidationError is the inner exception of your own error. Map the exception your FromException creates for unexpected failures to 500, because it otherwise inherits the mapping of your base exception. Map your own exception types, including their subclasses, and choose whether the message is safe to expose:

builder.Services.Configure<ResultHttpOptions>(o => o
    .Map<OrderShippedException>(StatusCodes.Status409Conflict, exposeMessage: true)
    .Map<UnexpectedDomainException>(StatusCodes.Status500InternalServerError));

The OpenAPI metadata of WithResultMapping lists 400 and 500 for errors only. Add .Produces(...) for the other statuses you map. A faulted Task is not converted: its exception goes through ASP.NET Core's exception handling.

Map errors that are data with onError. The switch makes the compiler check every case.

app.MapGet("/checkout/{id}", (int id) => Checkout(id).ToHttpResult(error => error switch
{
    CustomerNotFound => TypedResults.NotFound(),
    CartEmpty => TypedResults.BadRequest(),
    Unexpected => TypedResults.StatusCode(500)
}));

Documentation

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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.1.0 97 11/22/2026
1.0.0 98 11/21/2026
0.3.0 97 11/20/2026
0.2.0 100 11/19/2026
0.1.0 105 11/19/2026