MB.ResponseResult
1.0.3
See the version list below for details.
dotnet add package MB.ResponseResult --version 1.0.3
NuGet\Install-Package MB.ResponseResult -Version 1.0.3
<PackageReference Include="MB.ResponseResult" Version="1.0.3" />
<PackageVersion Include="MB.ResponseResult" Version="1.0.3" />
<PackageReference Include="MB.ResponseResult" />
paket add MB.ResponseResult --version 1.0.3
#r "nuget: MB.ResponseResult, 1.0.3"
#:package MB.ResponseResult@1.0.3
#addin nuget:?package=MB.ResponseResult&version=1.0.3
#tool nuget:?package=MB.ResponseResult&version=1.0.3
MB.ResponseResult Package 📦
A standardized API response library for ASP.NET Core, featuring multi-language support and seamless integration.
👅 Installation
dotnet add package MB.ResponseResult
🚀 Quick Start
- Register Services (Program.cs)
builder.Services.AddResponseResultServices(options =>
{
options.IsMultipleLang = true; // Enable multi-language support
});
🎯 Basic Usage (Response Type Breakdown)
✅ Success Responses
Method | Status Code | Usage Scenario | Example |
---|---|---|---|
ResponseCreated() |
201 | Resource creation success | ApiResponse.ResponseCreated(product) |
ResponseOk() |
200 | General success with/without data | ApiResponse.ResponseOk("Success") |
ResponseNoContent() |
204 | Successful operation with no content | ApiResponse.ResponseNoContent() |
❌ Error Responses
Method | Status Code | Usage Scenario | Example |
---|---|---|---|
ResponseNotFound() |
404 | Resource not found | ApiResponse.ResponseNotFound("User not found") |
ResponseBadRequest() |
400 | Invalid client request | ApiResponse.ResponseBadRequest(errors) |
ResponseValidationError() |
402 | Validation failures | ApiResponse.ResponseValidationError(errors) |
ResponseServerError() |
500 | Server-side errors | ApiResponse.ResponseServerError("Error") |
ResponseUnauthorized() |
401 | Missing/invalid authentication | ApiResponse.ResponseUnauthorized("Login required") |
ResponseForbidden() |
403 | Authenticated but unauthorized | ApiResponse.ResponseForbidden("Admin access required") |
ResponseConflict() |
409 | Data conflict (e.g., duplicate entry) | ApiResponse.ResponseConflict("Already exists") |
🔑 Key Features
Standardized Format
All responses follow the same consistent structure:
{
"data": {}, // Response payload (object)
"message": "Operation succeeded", // Human-readable message
"statusCode": 200, // HTTP status code
"status": true, // Boolean success indicator
"errors": [] // List of errors (if any)
}
Seamless Conversion
Convert ApiResponse to IActionResult automatically using:
.AsResult()
for synchronous responses
.AsResultAsync()
for asynchronous responses
🌍 Localization (Multi-Language Support)
Localization Ready
Message keys like "ProductRetrieved"
or "NotFound"
can be localized by implementing IResultLocalizationService
.
Implement a IResultLocalizationService Localization Service
public class CustomLocalizationService : IResultLocalizationService
{
public string GetLocalizedMessage(string messageKey, string languageCode)
{
//Your own logic
}
public Task<string> GetLocalizedMessageAsync(string messageKey, string languageCode)
{
//Your own logic
}
}
This README provides a quick guide to integrate and use the package effectively. Expand the documentation for advanced scenarios. 😊
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net9.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.