MxIO.ApiClient.WebExtensions.V2 1.1.148.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package MxIO.ApiClient.WebExtensions.V2 --version 1.1.148.1
                    
NuGet\Install-Package MxIO.ApiClient.WebExtensions.V2 -Version 1.1.148.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MxIO.ApiClient.WebExtensions.V2" Version="1.1.148.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MxIO.ApiClient.WebExtensions.V2" Version="1.1.148.1" />
                    
Directory.Packages.props
<PackageReference Include="MxIO.ApiClient.WebExtensions.V2" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MxIO.ApiClient.WebExtensions.V2 --version 1.1.148.1
                    
#r "nuget: MxIO.ApiClient.WebExtensions.V2, 1.1.148.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MxIO.ApiClient.WebExtensions.V2@1.1.148.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MxIO.ApiClient.WebExtensions.V2&version=1.1.148.1
                    
Install as a Cake Addin
#tool nuget:?package=MxIO.ApiClient.WebExtensions.V2&version=1.1.148.1
                    
Install as a Cake Tool

MxIO.ApiClient.WebExtensions.V2

This library provides extension methods for integrating API client responses with ASP.NET Core web applications, simplifying the process of converting API responses to appropriate HTTP responses.

Installation

dotnet add package MxIO.ApiClient.WebExtensions.V2

Features

  • Extension methods to convert ApiResponse objects to IActionResult
  • Extension methods to convert HttpResponseWrapper objects to IActionResult
  • Automatic HTTP status code mapping based on API response status
  • Preservation of error details in responses
  • Support for proper pagination headers

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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