Danom.MinimalApi 2.1.1

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

Danom.MinimalApi

NuGet Version build

Danom.MinimalApi is a library that provides a set of utilities to help integrate the Danom library with common tasks in ASP.NET Core Minimal API applications.

Key Features

  • Extension methods for converting Option<T> and Result<T, TError> types to IResult responses.
  • Support for both standard and typed results in Minimal APIs.

Design Goals

  • Simplify the handling of optional and result-based data in Minimal APIs.
  • Provide a clean and intuitive API for developers familiar with Danom and ASP.NET Core.

Getting Started

Install the Danom.MinimalApi NuGet package:

PM>  Install-Package Danom.MinimalApi

Or using the dotnet CLI

dotnet add package Danom.MinimalApi

Basic Usage

Returning Option

  • Some: Returns 200 OK with the value.
  • None: Return 404 Not Found (or a custom result, if provided).
app.MapGet("/user/{id}", (int id) => {
    var user = FindUser(id);
    return Results.Extensions.Option(user);
});

Or, with a custom result:

app.MapGet("/user/{id}", (int id) => {
    var user = FindUser(id);
    return Results.Extensions.Option(user, () => Results.Conflict());
});

Returning Result

  • Ok: Returns 200 OK with the value.
  • Error: Returns 400 Bad Request (or a custom IResult, if provided).
app.MapPost("/user", (User user) => {
    var result = TryCreateUser(user);
    return Results.Extensions.Result(result);
});

Or, with a custom result:

app.MapPost("/user", (User user) => {
    var result = TryCreateUser(user);
    return Results.Extensions.Result(result, error => Results.UnprocessableEntity());
});

Typed Results

If you want to use ASP.NET Core's typed results, Danom.MinimalApi provides additional extension methods.

Returning Typed Option

  • Some: Returns OptionHttpResult<T> and 200 OK.
  • None: Returns OptionHttpResult<T> and 404 Not Found (or a custom IResult, if provided).
using Danom;
using Danom.MinimalApi;

app.MapGet("/user/{id}", (int id) => {
    var user = FindUser(id);
    return DanomTypedResults.Option(user);
});

// or, with a custom error handler
app.MapGet("/user/{id}/custom", (int id) => {
    var user = FindUser(id);
    return DanomTypedResults.Option(user,
        noneResult: () => Results.NotFound("Custom not found!"));
});

Returning Typed Result

  • Ok: Returns ResultHttpResult<T, TError> and 200 OK.
  • Error: Returns ResultHttpResult<T, TError> and 400 Bad Request
using Danom;
using Danom.MinimalApi;

app.MapPost("/user", (User user) => {
    var result = TryCreateUser(user);
    return DanomTypedResults.Result(result);
});

// or, with a custom error handler
app.MapPost("/user/custom", (User user) => {
    var result = TryCreateUser(user);
    return DanomTypedResults.Result(result,
        errorResult: error => Results.Ok(new { Message = "There was a problem", error }));
});


// or, return a problem details response
app.MapPost("/user/problem", (User user) => {
    var result = TryCreateUser(user);
    return DanomTypedResults.ResultProblem(result);
});

Contributing

I kindly ask that before submitting a pull request, you first submit an issue.

If functionality is added to the API, or changed, please kindly update the relevant documentation. Unit tests must also be added and/or updated before a pull request can be successfully merged.

Only pull requests which pass all build checks and comply with the general coding standard can be approved.

Find a bug?

There's an issue for that.

License

Licensed under MIT.

Product 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. 
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
2.1.1 89 1/5/2026
2.1.0 92 12/30/2025
2.0.0 317 9/17/2025
2.0.0-beta4 199 6/24/2025