MX.Api.Web.Extensions
2.0.153.1
See the version list below for details.
dotnet add package MX.Api.Web.Extensions --version 2.0.153.1
NuGet\Install-Package MX.Api.Web.Extensions -Version 2.0.153.1
<PackageReference Include="MX.Api.Web.Extensions" Version="2.0.153.1" />
<PackageVersion Include="MX.Api.Web.Extensions" Version="2.0.153.1" />
<PackageReference Include="MX.Api.Web.Extensions" />
paket add MX.Api.Web.Extensions --version 2.0.153.1
#r "nuget: MX.Api.Web.Extensions, 2.0.153.1"
#:package MX.Api.Web.Extensions@2.0.153.1
#addin nuget:?package=MX.Api.Web.Extensions&version=2.0.153.1
#tool nuget:?package=MX.Api.Web.Extensions&version=2.0.153.1
MX.Api.Web.Extensions
This library provides ASP.NET Core integration as part of the MX API Abstractions approach. It offers extension methods for seamlessly integrating API client responses with ASP.NET Core web applications, simplifying the process of converting API responses to appropriate HTTP responses while maintaining consistency with the API design pattern.
Installation
dotnet add package MX.Api.Web.Extensions
Features
- Extension methods to convert ApiResponse<T> objects to IActionResult with proper status codes
- Extension methods to convert HttpResponseWrapper<T> objects to IActionResult
- Automatic HTTP status code mapping based on API response status
- Preservation of error details and metadata in HTTP responses
- Support for proper pagination headers following API design standards
- Seamless integration between MX.Api.Client and ASP.NET Core applications
Usage
Basic Usage in Controllers
[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
private readonly IUserApiClient _apiClient;
public UsersController(IUserApiClient apiClient)
{
_apiClient = apiClient;
}
[HttpGet("{id}")]
public async Task<IActionResult> GetUser(string id)
{
// Get data from your API client
var response = await _apiClient.GetUserAsync(id);
// Convert the API response to an appropriate HTTP response
return response.ToHttpResult();
}
[HttpGet]
public async Task<IActionResult> GetUsers([FromQuery] FilterOptions filter)
{
// Get collection from your API client
var response = await _apiClient.GetUsersAsync(filter);
// Convert the API response to an HTTP response with pagination headers
return response.ToHttpResult(HttpContext);
}
}
Working with Different Response Types
// Converting ApiResponse<T> to IActionResult
public async Task<IActionResult> GetResource(string id)
{
ApiResponse<ResourceDto> response = await _apiClient.GetResourceAsync(id);
return response.ToHttpResult();
}
// Converting HttpResponseWrapper<T> to IActionResult
public async Task<IActionResult> GetResource(string id)
{
HttpResponseWrapper<ResourceDto> wrapper = await _apiClient.GetResourceWithWrapperAsync(id);
return wrapper.ToHttpResult();
}
Adding Pagination Headers
When returning collections, you can add pagination headers to the response:
public async Task<IActionResult> GetResources([FromQuery] FilterOptions filter)
{
var response = await _apiClient.GetResourcesAsync(filter);
// Adds pagination headers to the HTTP response
return response.ToHttpResult(HttpContext);
}
Error Handling
The extension methods automatically handle error responses:
public async Task<IActionResult> CreateResource([FromBody] ResourceCreateDto dto)
{
var response = await _apiClient.CreateResourceAsync(dto);
// Will return appropriate status code and error details if creation fails
return response.ToHttpResult();
}
Advanced Usage
Custom Response Formatting
You can customize how responses are formatted:
public async Task<IActionResult> GetCustomFormattedResponse(string id)
{
var response = await _apiClient.GetResourceAsync(id);
return response.ToHttpResult(formatResponse: result =>
{
// Custom response formatting
return new
{
resource = result,
timestamp = DateTime.UtcNow,
version = "1.0"
};
});
}
License
GPL-3.0-only
| 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.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Options (>= 9.0.6)
- MX.Api.Abstractions (>= 2.0.153.1)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.2.40 | 282 | 2/1/2026 |
| 2.2.34 | 102 | 1/31/2026 |
| 2.2.31 | 235 | 1/24/2026 |
| 2.2.9 | 508 | 11/30/2025 |
| 2.2.8 | 123 | 11/29/2025 |
| 2.2.7 | 121 | 11/29/2025 |
| 2.2.6 | 127 | 11/29/2025 |
| 2.2.5 | 134 | 11/29/2025 |
| 2.2.4 | 127 | 11/29/2025 |
| 2.2.3 | 123 | 11/29/2025 |
| 2.2.2 | 134 | 11/29/2025 |
| 2.2.1 | 131 | 11/29/2025 |
| 2.1.5.1-preview | 107 | 11/29/2025 |
| 2.1.4 | 125 | 11/29/2025 |
| 2.1.0-preview | 103 | 11/29/2025 |
| 2.0.200.1 | 121 | 11/29/2025 |
| 2.0.196.1 | 299 | 11/13/2025 |
| 2.0.195.1 | 965 | 11/6/2025 |
| 2.0.194.1 | 195 | 10/30/2025 |
| 2.0.153.1 | 107 | 7/5/2025 |