Kodster.Results.AspNetCore 0.1.0

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

Kodster.Results.AspNetCore

Turns a failed Kodster.Results Result into an RFC 7807 ProblemDetails response.

dotnet add package Kodster.Results.AspNetCore

Depends on Kodster.Results and the ASP.NET Core shared framework. Targets .NET 10.

Usage

One extension method, ToProblemDetails(), on any Result:

app.MapGet("users/{id:guid}", async (
    Guid id,
    IUserService users,
    CancellationToken cancellationToken) =>
{
    var result = await users.Find(id, cancellationToken);

    return result.IsSuccess
        ? Results.Ok(result.Value)
        : result.ToProblemDetails();
});

Calling it on a successful result throws InvalidOperationException — it is only ever the failure branch.

Status mapping

The ErrorType on the error decides the status code, title and type URI:

ErrorType Status Title
Validation 400 Bad Request
Unauthorized 401 Unauthorized
PaymentRequired 402 Payment Required
Forbidden 403 Forbidden
NotFound 404 Not Found
Conflict 409 Conflict
Gone 410 Gone
PreconditionFailed 412 Precondition Failed
Failure 500 Internal Server Error

The type field links to the relevant RFC section for the status code.

The errors member

Every response carries an errors extension member, so clients read failures from one place regardless of how many there were.

A plain failure carries its single error:

{
  "type": "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4",
  "title": "Not Found",
  "status": 404,
  "errors": [
    { "code": "User.NotFound", "description": "User was not found.", "type": 3 }
  ]
}

A ValidationResult carries all of them:

{
  "type": "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1",
  "title": "Bad Request",
  "status": 400,
  "errors": [
    { "code": "Nickname", "description": "Nickname is required.", "type": 1 },
    { "code": "Age", "description": "Age must be 13 or older.", "type": 1 }
  ]
}

Note that type inside an error is the ErrorType ordinal, not a string. Clients that switch on it are coupled to those numbers, which is why ErrorType only ever gains members by appending.

Companion packages

  • Kodster.Results — the Result and Error types this maps from. No dependencies.
  • Kodster.CQRS — request/handler abstraction whose handlers return those results.

License

MIT

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
0.1.0 111 8/19/2026