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.
Install
| Product | Versions |
|---|---|
| .NET |
README
MinimalApi.Results
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 usingApiResponse<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 throughFluentValidationviaValidationFilter<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
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.