Skip to main content

RA.Utilities.Api

· 3 min read
Redon Alla
.NET, React, Angular Developer

Version 10.0.0

Date Badge NuGet version

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

Date Badge NuGet version

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 IExceptionHandler implementation 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.
  • Endpoint Registration Helpers (AddEndpoints & MapEndpoints):

    • Provides a clean pattern for organizing API endpoints into separate files using the IEndpoint interface.
    • Keeps Program.cs clean and maintainable by automatically discovering and registering all endpoint implementations in your project.
  • Standardized Success Response Helpers (SuccessResponse):

    • Added a new static SuccessResponse class 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.
  • Seamless Result<T> Integration:

    • The SuccessResponse helpers and the exception handling middleware work together to provide a clean way to handle the Result<T> type from RA.Utilities.Core.
    • Use the Match method on a Result to map success outcomes to SuccessResponse.Ok() and failure outcomes directly to an exception that the middleware will handle.
  • Comprehensive Documentation:

    • The README.md has been completely rewritten to provide clear, step-by-step instructions and usage examples for all major features.

🚀 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();