Skip to main content
net8.0net9.0

It provides a consistent response structure via the ApiResponse class, supports error handling in compliance with RFC7807, integrates with FluentValidation, and includes middleware for performance logging.

Published
Jul 17, 2025
1y ago
Total Downloads
1.5K
1,471

Install

dotnet add package MinimalApi.Results --version 1.0.6
ProductVersions
.NET
net8.0net9.0

README

MinimalApi.Results

NuGet Version NuGet Downloads

MinimalApi.Results is a lightweight and modular library designed to streamline response handling in .NET Minimal APIs.

It provides a consistent response structure via the ApiResponse<T> class, supports error handling in compliance with RFC7807 through ProblemDetails, integrates seamlessly with FluentValidation, and includes middleware for performance logging and execution time monitoring.

This library aims to enhance the robustness, clarity, and maintainability of Minimal API-based applications.


✨ Key Features

  • âś… Standardized API Responses
    Uniform return structure using ApiResponse<T> for all endpoints.

  • 📊 Performance Logging Middleware
    Measure and log execution time per endpoint, with optional threshold alerting.

  • đź§Ş Model Validation Integration
    Built-in support for model validation through FluentValidation via ValidationFilter<T>.


📦 Installation

You can install the package using the .NET CLI:

dotnet add package MinimalApi.Results

Or via the Package Manager Console:

Install-Package MinimalApi.Results

🚀 Usage Examples

Basic Usage with Standardized Response

app.MapPost("/example", async ([FromBody] MyRequest request) =>
{
    var result = DoSomething(request);
    return ApiResponse<MyResponse>.Ok(result, "/example").ToResult();
});

With Model Validation using FluentValidation

app.MapPost("/example", async ([FromBody] MyRequest request) =>
{
    var result = DoSomething(request);
    return ApiResponse<MyResponse>.Ok(result, "/example").ToResult();
})
.AddEndpointFilter<ValidationFilter<MyRequest>>();

With FluentValidation and Execution Time Monitoring

Ensure the middleware is registered in the correct order:

app.UseMiddleware<ApiResponsePostProcessorMiddleware>();
app.UseMiddleware<PerformanceLoggingMiddleware>();

app.MapPost("/example", async ([FromBody] MyRequest request) =>
{
    var result = DoSomething(request);
    return ApiResponse<MyResponse>.Ok(result, "/example").ToResult();
})
.WithMetadata(new MaxExecutionTimeAttribute(200)) // Execution time threshold in milliseconds
.AddEndpointFilter<ValidationFilter<MyRequest>>();

đź“„ License

This project is licensed under the MIT License.


🙋‍♂️ Contributions

Contributions, feedback, and suggestions are welcome. Please feel free to open issues or submit pull requests to help improve the project.

Changes from Previous Version

No structural changes between v1.0.4 and v1.0.6.

Adoption Assessment

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

Compatibility metadata lists 2 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.