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
<PackageReference Include="Toarnbeike.Results.MinimalApi" Version="1.0.0" />
<PackageVersion Include="Toarnbeike.Results.MinimalApi" Version="1.0.0" />
<PackageReference Include="Toarnbeike.Results.MinimalApi" />
paket add Toarnbeike.Results.MinimalApi --version 1.0.0
#r "nuget: Toarnbeike.Results.MinimalApi, 1.0.0"
#:package Toarnbeike.Results.MinimalApi@1.0.0
#addin nuget:?package=Toarnbeike.Results.MinimalApi&version=1.0.0
#tool nuget:?package=Toarnbeike.Results.MinimalApi&version=1.0.0
Toarnbeike.Results.MinimalApi
Seamlessly return Toarnbeike.Results from your Minimal API endpoints with automatic HTTP response mapping.
Features
- Automatic mapping of
Result
andResult<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);
}
}
Recommended approach: group filter
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 | Versions 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. |
-
net9.0
- Toarnbeike.Results (>= 1.0.0)
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 |