MinimalApi.Results
1.0.7
dotnet add package MinimalApi.Results --version 1.0.7
NuGet\Install-Package MinimalApi.Results -Version 1.0.7
<PackageReference Include="MinimalApi.Results" Version="1.0.7" />
<PackageVersion Include="MinimalApi.Results" Version="1.0.7" />
<PackageReference Include="MinimalApi.Results" />
paket add MinimalApi.Results --version 1.0.7
#r "nuget: MinimalApi.Results, 1.0.7"
#:package MinimalApi.Results@1.0.7
#addin nuget:?package=MinimalApi.Results&version=1.0.7
#tool nuget:?package=MinimalApi.Results&version=1.0.7
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 throughFluentValidation
viaValidationFilter<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.
Product | Versions 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 was computed. 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. |
-
net8.0
- FluentValidation (>= 12.0.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Logging (>= 9.0.7)
- System.Text.Json (>= 9.0.7)
-
net9.0
- FluentValidation (>= 12.0.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Logging (>= 9.0.7)
- System.Text.Json (>= 9.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.