Maple.Result.Extensions.AspNetCore 0.12.1

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

Maple.Result.Extensions.AspNetCore

Maps the Maple.Result to the HTTP response (ASP.NET Core MVC version)

This package maps to the MVC ActionResult. For Minimal APIs use Maple.Result.Extensions.MinimalApi.

Project status: EARLY STAGE

Check also my libraries:

Give it a star ⭐

Do you like it? Show your support by giving this project a star!

Status

✅ Basic mapping without configuration.
✅ Integration tests.
✅ Configuration passed as a parameter to the extension method.
✅ Support for global configuration.
✅ Support for multiple successful codes.
✅ Support for Created (201) with Location header.
🔲 Documentation.

Usage

using Maple.Result;
using Maple.Result.Extensions.AspNetCore;

// Success -> 204 No Content, error -> RFC 9457 problem details
[HttpDelete("{id}")]
public ActionResult Delete(int id)
    => _orderService.Delete(id).ToActionResult(this);

// Success -> 200 OK with the value (204 No Content when the value is null)
[HttpGet("{id}")]
public ActionResult Get(int id)
    => _orderService.Get(id).ToActionResult(this);

// Success -> the given status code
[HttpPost]
public ActionResult Create(Order order)
    => _orderService.Create(order).ToActionResult(this, HttpStatusCode.Created);

// Errors -> mapped explicitly; the default mapping is used when the mapping returns null
[HttpDelete("{id}/lines")]
public ActionResult DeleteLines(int id)
    => _orderService.DeleteLines(id).ToActionResult(this,
        (error, controller) => error.Category == ErrorCategory.Conflict
            ? controller.StatusCode(StatusCodes.Status410Gone)
            : null);

The same error mapping can be registered once for the whole application, in which case it is used whenever no mapping is passed to the extension method:

builder.Services.ConfigureResultMapping(options => options.ErrorMappings.Add(
    (error, controller) => error.Category == ErrorCategory.Conflict
        ? controller.StatusCode(StatusCodes.Status410Gone)
        : null));

Example Error Response

Example

{
    "type": "https://example.com/probs/out-of-credit",
    "title": "You do not have enough credit.",
    "status": 400,
    "detail": "Your current balance is 30, but that costs 50.",
    "instance": "/accounts/12345/msgs/abc",
    "errors": [
        {
            "pointer": "#/age",
            "detail": "must be a positive integer",
            "detailTemplated": {
                "templateId":"user.details.age.mustBePositive"
            }
        },
        {
            "pointer": "#/profile/colour",
            "detail": "must be ‘green’, ‘red’ or ‘blue’",
            "detailTemplated": {
                "templateId": "user.profile.colour",
                "params": {
                    "validValueIds": [
                        "user.profile.colour.green",
                        "user.profile.colour.red",
                        "user.profile.colour.blue"
                    ]
                }
            }
        }
    ],
    "detailTemplated": {
        "templateId": "user.account.balance.tooLow",
        "params": {
            "errorCode": "UAB17",
            "accounts": [
                {
                    "title": "Main (***9456)",
                    "url": "/accounts/12345"
                },
                {
                    "title": "Main (***3357)",
                    "url": "/accounts/67890"
                }
            ],
            "currentBalance": 30,
            "requiredBalance": 50
        }
    }

}

See also

Contribution

Please contact author: engineer(at sign)blumail(dot)me

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.12.1 96 8/31/2026
0.11.0 94 8/31/2026
0.9.0 108 8/27/2026
0.2.5 147 3/6/2026
0.2.0 120 3/2/2026