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

ASP.NET Core Minimal API support for Danom.

Published
Dec 30, 2025
9mo ago
Total Downloads
1.0K
1,038

Install

dotnet add package Danom.MinimalApi --version 2.1.0
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) =>
{
    Option<User> user = FindUser(id);
    return Results.Extensions.Option(user);
});

Or, with a custom result:

app.MapGet("/user/{id}", (int id) =>
{
    Option<User> 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 result, if provided).
app.MapPost("/user", (User user) =>
{
    Result<User, string> result = TryCreateUser(user);
    return Results.Extensions.Result(result);
});

Or, with a custom result:

app.MapPost("/user", (User user) =>
{
    Result<User, string> 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 TypedResults.Ok(value) and 200 OK.
  • None: Returns TypedResults.NotFound() and 404 Not Found (or a custom result, if provided).
using Danom.MinimalApi.TypedResults;

app.MapGet("/user/{id}", (int id) =>
{
    Option<User> user = FindUser(id);
    // returns TypedResults.Ok(user) or TypedResults.NotFound()
    return Results.Extensions.Option(user);
});

### Returning Typed Result

- **Ok**: Returns `TypedResults.Ok(value)` and `200 OK`.
- **Error**: Returns `TypedResults.BadRequest(error)` and `400 Bad Request`

```csharp
using Danom.MinimalApi.TypedResults;

app.MapPost("/user", (User user) =>
{
    Result<User, ResultErrors> result = TryCreateUser(user);
    // returns TypedResults.Ok(user) or TypedResults.BadRequest(errors)
    return Results.Extensions.Result(result);
});

Find a bug?

There's an issue for that.

License

Licensed under MIT.

Changes from Previous Version

v2.0.0v2.1.0
Added Frameworks
net10.0
Added Dependencies
Danom(net10.0)

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.