Maple.Result.Extensions.Functions.Worker 0.2.0

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

Maple.Result.Extensions.Functions.Worker

Maps the Maple.Result to the HTTP response (Azure Functions isolated worker model version)

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.
✅ Unit and integration tests.
✅ Custom error mapping passed as a parameter to the extension method.
✅ Custom error mapping registered in the service collection.
✅ Support for custom successful status codes.
🔲 Documentation.

Scope

This package targets the Azure Functions isolated worker model with the ASP.NET Core integration disabled, where an HTTP trigger takes an HttpRequestData and returns an HttpResponseData. When the ASP.NET Core integration is enabled, the trigger works with HttpRequest/IActionResult instead, and Maple.Result.Extensions.AspNetCore or Maple.Result.Extensions.MinimalApi applies.

The worker model references neither ASP.NET Core nor its ProblemDetails type, so this package writes the RFC 9457 body itself, with the application/problem+json content type.

Usage

using Maple.Result.Extensions.Functions.Worker;

// Success -> 204 No Content, error -> RFC 9457 problem details
[Function("DeleteOrder")]
public HttpResponseData Delete([HttpTrigger(AuthorizationLevel.Function, "delete", Route = "orders/{id}")] HttpRequestData request, int id)
{
    return orderService.Delete(id).ToHttpResponseData(request);
}

// Success -> 200 OK with the value (204 No Content when the value is null)
[Function("GetOrder")]
public HttpResponseData Get([HttpTrigger(AuthorizationLevel.Function, "get", Route = "orders/{id}")] HttpRequestData request, int id)
{
    return orderService.Get(id).ToHttpResponseData(request);
}

// Success -> the given status code
[Function("CreateOrder")]
public HttpResponseData Create([HttpTrigger(AuthorizationLevel.Function, "post", Route = "orders")] HttpRequestData request, Order order)
{
    return orderService.Create(order).ToHttpResponseData(request, HttpStatusCode.Created);
}

// Success -> mapped explicitly, e.g. to return the Location header
[Function("CreateOrderWithLocation")]
public HttpResponseData CreateWithLocation([HttpTrigger(AuthorizationLevel.Function, "post", Route = "orders")] HttpRequestData request, Order order)
{
    return orderService.Create(order).ToHttpResponseData(request, (Order created, HttpRequestData req) =>
    {
        var response = Result<Order>.FromValue(created).ToHttpResponseData(req, HttpStatusCode.Created);
        response.Headers.Add("Location", $"orders/{created.Id}");

        return response;
    });
}

// Errors -> mapped explicitly; the default mapping is used when the mapping returns null
[Function("ListOrders")]
public HttpResponseData List([HttpTrigger(AuthorizationLevel.Function, "get", Route = "orders")] HttpRequestData request)
{
    return orderService.GetAll().ToHttpResponseData(request,
        (error, req) => error.Category == ErrorCategory.Conflict ? req.CreateResponse(HttpStatusCode.Gone) : null);
}

Custom error mappings can also be registered once for the whole worker. They are evaluated after the mapping passed to the extension method, and in the order they were added:

var builder = FunctionsApplication.CreateBuilder(args);

builder.Services.ConfigureResultMapping(options =>
        options.ErrorMappings.Add((error, request) => error.Category == ErrorCategory.Conflict
            ? request.CreateResponse(HttpStatusCode.Gone)
            : null));

await builder.Build().RunAsync();

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
        }
    }
}

Unlike the ASP.NET Core versions, the response carries no traceId extension: the isolated worker model has no equivalent of the ASP.NET Core Problem Details service adding it.

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.2.0 107 9/2/2026