Toarnbeike.Results.MinimalApi 1.0.0

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

NuGet

CI Code Coverage .NET 9 License: MIT

Toarnbeike.Results.MinimalApi

Seamlessly return Toarnbeike.Results from your Minimal API endpoints with automatic HTTP response mapping.


Features

  • Automatic mapping of Result and Result<TValue> types to IResult using an EndpointFilter
  • Built-in mappers for common failures to standardized ProblemDetails responses
  • Support for custom mappers to override or extend default behavior
  • Fully configurable through dependency injection

Getting started

dotnet add package Toarnbeike.Results.MinimalApi

This package targets .NET 9+ and depends on:


Usage

Register result mapping

Add result mappping support to your DI container:

  builder.Services.AddResultMapping();

Apply the endpoint filter

Apply the ResultMappingEndpointFilter to any endpoint that returns a Result or Result<TValue>:

  App.MapGet("customer/{id}", (int id, ICustomerService service) =>
  {
      Result<Customer> result = service.GetById(id);
      return result;
  }).AddEndpointFilter<ResultMappingEndpointFilter>();

Mapping behavior

Result Type HTTP Response
Result<T>.Success(value) 200 OK with value as JSON payload
Result<T>.Success() 204 No Content
Result<T>.Failure(failure) ProblemDetails response (status code based on failure type)

Custom failures can be mapped by registing your own mappers:

  builder.Services.AddResultMapping(options =>
  {
      options.AddMapper<ConflictFailureMapper>();                           // add single mapper
      options.AddMappersFromAssemblyContaining<ConflictFailureMapper>();    // add all mappers from an assembly
      options.UseFallback<CustomFallbackMapper>();                          // override the default fallback mapper for unmapped failures
  });

  public class ConflictFailureMapper : FailureResultMapper<ConflictFailure>
  {
      public ProblemDetails Map(CustomFailure failure)
      {
          return Problem(failure.Message, statusCode: 409);
      }
  }

To avoid repeating .AddEndpointFilter<ResultMappingEndpointFilter>() on every endpoint, you can use the MapResultGroup() extension method to apply the filter to a group of endpoints:

  var group = app.MapResultGroup("/customers");

  group.MapGet("/{id}", (int id, ICustomerService service) =>
  {
    Result<Customer> result = service.GetById(id);
    return result;
  });

Every endpoint in the group will automatically map Result and Result<TValue> types to appropriate HTTP responses.

If you rely on Result mapping for all endpoints in your application, you can create a /api group for all endpoints:

  var endpoints = app.MapResultGroup("/api");

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 180 8/28/2025