RA.Utilities.Api.Results
RA.Utilities.Api.Results provides a standardized set of models for creating consistent API responses within the RA.Utilities ecosystem.
This package includes generic wrappers for success, error, and validation failure scenarios, helping to streamline API development and improve client-side handling.
๐ฏ Purposeโ
When building APIs, it's crucial to have a consistent and predictable response structure. This package provides a set of ready-to-use C# records that can be returned from your ASP.NET Core controller actions. These models ensure that every responseโwhether it's a success, a generic error, or a detailed validation failureโhas the same shape, making it easier for clients to parse and handle.
This library is designed to work seamlessly with the other RA.Utilities packages, such as RA.Utilities.Core.Constants
for status codes and messages.
๐ ๏ธ Installationโ
You can install the package via the .NET CLI:
dotnet add package RA.Utilities.Api.Results
Or through the NuGet Package Manager console:
Install-Package RA.Utilities.Api.Results
Or through the NuGet Package Manager in Visual Studio.
๐ Dependenciesโ
๐๏ธ Response<T>
The Response class is the universal wrapper for all API responses within the RA.Utilities ecosystem. It provides a standardized structure for returning data, errors, and status information from your API endpoints, ensuring consistency and predictability for clients.
๐๏ธ SuccessResponse<T>
The SuccessResponse class is a specialized model for creating standardized, successful API responses.
๐๏ธ BadRequestResponse
The BadRequestResponse class is a specialized model for creating standardized 400 Bad Request responses, typically used to communicate validation failures to the client. It inherits from Response, with the Result property typed as an array of BadRequestResult objects.
๐๏ธ NotFoundResponse
The NotFoundResponse class is a specialized model for creating standardized 404 Not Found responses.
๐๏ธ ConflictResponse
The ConflictResponse class is a specialized model for creating standardized 409 Conflict responses.
๐๏ธ ErrorResponse
The ErrorResponse class is a specialized model for creating standardized 500 Internal Server Error responses.
๐๏ธ UnauthorizedResponse
The UnauthorizedResponse class is a specialized Data Transfer Object (DTO) designed to create a standardized and consistent JSON response body whenever your API needs to return an HTTP 401 Unauthorized error.