Hesham.ResultPattern.Extension.MinimalAPI
1.1.2
dotnet add package Hesham.ResultPattern.Extension.MinimalAPI --version 1.1.2
NuGet\Install-Package Hesham.ResultPattern.Extension.MinimalAPI -Version 1.1.2
<PackageReference Include="Hesham.ResultPattern.Extension.MinimalAPI" Version="1.1.2" />
<PackageVersion Include="Hesham.ResultPattern.Extension.MinimalAPI" Version="1.1.2" />
<PackageReference Include="Hesham.ResultPattern.Extension.MinimalAPI" />
paket add Hesham.ResultPattern.Extension.MinimalAPI --version 1.1.2
#r "nuget: Hesham.ResultPattern.Extension.MinimalAPI, 1.1.2"
#:package Hesham.ResultPattern.Extension.MinimalAPI@1.1.2
#addin nuget:?package=Hesham.ResultPattern.Extension.MinimalAPI&version=1.1.2
#tool nuget:?package=Hesham.ResultPattern.Extension.MinimalAPI&version=1.1.2
ResultPattern.Extension.MinimalAPI
Minimal API response helpers for ResultPattern.
Maps Result<TValue> and List<Error> directly to standards-compliant HTTP Problem Details responses — with zero boilerplate.
📦 Installation
dotnet add package ResultPattern.Extension.MinimalAPI
Requires:
ResultPatterncore package.
🚀 Quick Start
1. Register Services
builder.Services.AddResponseHelper();
2. Inject and Use in Endpoints
app.MapGet("/basket/{userName}", async (
string userName,
ISender sender,
ResponseHelper responseHelper,
CancellationToken ct) =>
{
var query = new GetBasketQuery(userName);
Result<GetBasketResult> result = await sender.Send(query, ct);
return result.Match(
val => Results.Ok(val.Adapt<GetBasketResponse>()),
responseHelper.ToProblemResult);
})
ResponseHelper is registered as a scoped service. Inject it directly into your endpoint delegate and pass responseHelper.ToProblemResult as the error branch of Match — no extra wiring needed.
ResponseHelper
The core service exposed by this package. It takes a List<Error> and produces an IResult shaped as an RFC 7807 Problem Details response.
ToProblemResult(List<Error> errors)
The main entry point. Inspects the error list and delegates to the appropriate response builder:
| Condition | Response Type | Status Code |
|---|---|---|
All errors are 422 Unprocessable Entity |
ValidationProblem |
422 |
| Mixed or single non-validation error | Problem |
Error's own HttpStatusCode |
| Empty error list | Generic Problem |
500 |
Response Shapes
Validation Errors — 422 Unprocessable Entity
Triggered when all errors in the list carry a 422 status code (i.e. all created via Error.Validation(...)).
All descriptions are collected, deduplicated, and returned under a single "errors" key.
{
"title": "Validation",
"status": 422,
"detail": "One or more validation errors occurred.",
"errors": {
"errors": [
"Name cannot be null or empty.",
"Name cannot be less than 3 characters.",
"Invalid email address."
]
}
}
In Development, each error's full stack trace is appended under extensions.stackTraces:
{
"title": "Validation",
"status": 422,
"detail": "One or more validation errors occurred.",
"errors": {
"errors": [
"Name cannot be null or empty.",
"Invalid email address."
]
},
"extensions": {
"stackTraces": [
{
"description": "Name cannot be null or empty.",
"stackTrace": {
"memberName": "Create",
"fileName": "User.cs",
"lineNumber": 12
}
},
{
"description": "Invalid email address.",
"stackTrace": {
"memberName": "Create",
"fileName": "User.cs",
"lineNumber": 18
}
}
]
}
}
Single / Mixed Errors — Problem Details
Triggered when errors are not all 422 — e.g. 404, 403, 409, or 500.
The first error in the list drives the response status and title.
{
"title": "NotFound",
"status": 404,
"detail": "Restaurant with id '5' not found."
}
In Development, the error's stack trace is appended under extensions.stackTrace:
{
"title": "NotFound",
"status": 404,
"detail": "Restaurant with id '5' not found.",
"extensions": {
"stackTrace": {
"memberName": "Handle",
"fileName": "DeleteRestaurantCommandHandler.cs",
"lineNumber": 14
}
}
}
Stack traces are never exposed in Production. The
IHostEnvironmentis checked internally — no configuration required.
Environment-Aware Diagnostics
ResponseHelper automatically adjusts its response detail based on the current environment:
| Field | Development | Production |
|---|---|---|
extensions.stackTrace |
✅ Included | ❌ Omitted |
extensions.stackTraces |
✅ Included | ❌ Omitted |
| Error descriptions | ✅ Included | ✅ Included |
| HTTP status codes | ✅ Included | ✅ Included |
Full Endpoint Example
A complete delete endpoint using ResultPattern and ResponseHelper together:
app.MapDelete("/restaurants/{id}", async (
Guid id,
ISender sender,
ResponseHelper responseHelper,
CancellationToken ct) =>
{
var command = new DeleteRestaurantCommand(id);
Result<Success> result = await sender.Send(command, ct);
return result.Match(
_ => Results.NoContent(),
responseHelper.ToProblemResult);
})
.RequireAuthorization();
app.MapPost("/users", async (
CreateUserRequest request,
ISender sender,
ResponseHelper responseHelper,
CancellationToken ct) =>
{
var command = new CreateUserCommand(request.Name, request.Email);
Result<UserResponse> result = await sender.Send(command, ct);
return result.Match(
user => Results.Created($"/users/{user.Id}", user),
responseHelper.ToProblemResult);
})
MVC & Web API vs Minimal API
Both extension packages expose an identical ResponseHelper API surface and produce the same Problem Details response shapes. Choose based on how your application is structured:
ResultPattern.Extension.MinimalAPI |
ResultPattern.Extension.MVC |
|
|---|---|---|
| Return type | IResult |
ActionResult |
| Factory | Results.Problem / Results.ValidationProblem |
ProblemDetailsFactory |
HttpContext source |
Endpoint delegate parameter | IHttpContextAccessor |
| Use in | app.Map* endpoint delegates |
ControllerBase subclasses (MVC & Web API) |
| Stack trace in Dev | ✅ Yes | ✅ Yes |
Related Packages
| Package | Purpose |
|---|---|
ResultPattern |
Core Result<T>, Error, Ensure, Combine |
ResultPattern.Extension.MinimalAPI |
This package — HTTP Problem Details mapping for Minimal APIs |
ResultPattern.Extension.MVC |
HTTP Problem Details mapping for MVC & Web API Controllers |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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 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. |
-
net10.0
- Hesham.ResultPattern (>= 1.1.2)
-
net8.0
- Hesham.ResultPattern (>= 1.1.2)
-
net9.0
- Hesham.ResultPattern (>= 1.1.2)
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.2 | 71 | 3/1/2026 |