Skip to main content
net8.0net9.0net10.0

ASP.NET Core Minimal API support for Danom.

Published
Jan 5, 2026
9mo ago
Total Downloads
1.0K
1,038

Install

dotnet add package Danom.MinimalApi --version 2.1.1
ProductVersions
.NET
net10.0net8.0net9.0

README

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.

Changes from Previous Version

No structural changes between v2.1.0 and v2.1.1.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.