RA.Utilities.Api
Version 10.0.2
Add CreatedAtRoute methods to SuccessResponse for enhanced API response handling.
Version 10.0.1
✨ New Features: FluentValidation Integration for Minimal APIs
This release introduces a comprehensive integration with FluentValidation for ASP.NET Core Minimal APIs. You can now effortlessly validate incoming requests and automatically reflect those validation rules in your OpenAPI (Swagger) documentation. This creates a single source of truth for your validation logic, improving maintainability and providing a better experience for your API consumers.
1. Automatic Request Validation
A new endpoint filter has been introduced that automatically validates API request models. By simply adding .Validate<TModel>() to your endpoint definition, you can ensure that all incoming data is valid before your handler logic is executed. If validation fails, a standardized 400 Bad Request response is returned with detailed error information.
How to use it:
Chain the .Validate<TModel>() extension method to your endpoint registration.
// In your endpoint definition
app.MapPost("/users", (CreateUserRequest user) => {
// Handler logic here...
return SuccessResponse.Created(user);
})
.Validate<CreateUserRequest>(); // This enables automatic validation
This leverages the ValidationEndpointFilter<TModel>, which resolves your IValidator<TModel> implementations from the dependency injection container and executes them.
Version 10.0.0
Changed project version from a release candidate to final version 10.0.0 for production readiness.
Revised XML documentation comments to improve clarity and detail.
Improved the documentation in IEndpoint to clarify its purpose in grouping related API endpoints.
Adjusted parameter and return type descriptions in EndpointExtensions for better understanding of default assembly behavior.
Enhanced comments in SuccessResponse to explicitly state response wrapping behavior.
Version 10.0.0-rc.2
This release modernizes the RA.Utilities.Api package, introducing a suite of tools to build robust, consistent, and maintainable ASP.NET Core APIs. Key features include a .NET 8 global exception handler, helpers for standardized success responses, and a clean pattern for endpoint registration.
✨ New Features & Improvements
-
Global Exception Handling (
AddRaExceptionHandling):- Introduced a .NET 8
IExceptionHandlerimplementation that automatically catches exceptions and transforms them into standardized JSON error responses. - Catches semantic exceptions from
RA.Utilities.Core.Exceptions(e.g.,NotFoundException,ConflictException) and maps them to the correct HTTP status codes (404, 409, etc.). - Handles any unhandled exceptions by returning a generic 500 Internal Server Error to prevent leaking sensitive information.
- Introduced a .NET 8
-
Endpoint Registration Helpers (
AddEndpoints&MapEndpoints):- Provides a clean pattern for organizing API endpoints into separate files using the
IEndpointinterface. - Keeps
Program.csclean and maintainable by automatically discovering and registering all endpoint implementations in your project.
- Provides a clean pattern for organizing API endpoints into separate files using the
-
Standardized Success Response Helpers (
SuccessResponse):- Added a new static
SuccessResponseclass with helper methods (Ok,Created,NoContent, etc.). - These helpers simplify the creation of successful API responses and automatically wrap the payload in the standard
SuccessResponse<T>model, ensuring consistency with error responses.
- Added a new static
-
Seamless
Result<T>Integration:- The
SuccessResponsehelpers and the exception handling middleware work together to provide a clean way to handle theResult<T>type fromRA.Utilities.Core. - Use the
Matchmethod on aResultto map success outcomes toSuccessResponse.Ok()and failure outcomes directly to an exception that the middleware will handle.
- The
-
Comprehensive Documentation:
- The
README.mdhas been completely rewritten to provide clear, step-by-step instructions and usage examples for all major features.
- The
🚀 Getting Started
Register the services in your Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRaExceptionHandling();
builder.Services.AddEndpoints();
var app = builder.Build();
app.UseRaExceptionHandling();
app.MapEndpoints();