RA.Utilities.Api.Middlewares
· 2 min read
Version 10.0.10-rc.2
This release focuses on significantly improving the documentation and clarifying the purpose and usage of the middlewares provided in this package. The goal is to make it easier for developers to implement robust logging and header validation in their APIs.
✨ New Features & Improvements
-
HttpLoggingMiddleware:- Provides high-performance HTTP request/response logging suitable for production environments.
- Uses
Microsoft.IO.RecyclableMemoryStreamto minimize memory allocations and GC pressure. - Integrates with
RA.Utilities.Logging.Sharedto produce structured logs, making them easy to query and analyze. - Includes configurable options to exclude specific paths (e.g.,
/swagger,/health) from logging.
-
DefaultHeadersMiddleware:- Enforces the presence of required headers, such as
X-Request-Id, to ensure traceability in distributed systems. - Automatically returns a standardized
400 Bad Requestresponse using models fromRA.Utilities.Api.Resultsif a required header is missing. - Includes configurable options to ignore header validation for specific paths.
- Enforces the presence of required headers, such as
-
Simplified Registration:
- Introduced extension methods (
AddHttpLoggingMiddleware,AddDefaultHeadersMiddleware) for clean and simple registration inProgram.cs.
- Introduced extension methods (
-
Updated Documentation:
- The
README.mdhas been updated to reflect the latest usage patterns and best practices, with clear code examples for .NET 8.
- The
🚀 Getting Started
Register the middlewares in your Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpLoggingMiddleware();
builder.Services.AddDefaultHeadersMiddleware();
var app = builder.Build();
app.UseMiddleware<HttpLoggingMiddleware>();
app.UseMiddleware<DefaultHeadersMiddleware>();