MingoLib 1.13.0

dotnet add package MingoLib --version 1.13.0
                    
NuGet\Install-Package MingoLib -Version 1.13.0
                    
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="MingoLib" Version="1.13.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MingoLib" Version="1.13.0" />
                    
Directory.Packages.props
<PackageReference Include="MingoLib" />
                    
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 MingoLib --version 1.13.0
                    
#r "nuget: MingoLib, 1.13.0"
                    
#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 MingoLib@1.13.0
                    
#: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=MingoLib&version=1.13.0
                    
Install as a Cake Addin
#tool nuget:?package=MingoLib&version=1.13.0
                    
Install as a Cake Tool

MingoLib.ClientFactory A comprehensive HTTP client wrapper for .NET applications that simplifies API interactions while providing robust error handling and logging. Features

🚀 Full HTTP Method Support: GET, POST, PUT, PATCH, DELETE 🛡️ Robust Error Handling: Custom exception type with detailed context 📝 Comprehensive Logging: Request/response logging with appropriate detail levels 🔄 Flexible Content Types: Support for JSON and form data 🧩 Extensible Design: Clean interface for easy testing and extension 📊 Structured Response Models: Generic response models with support for custom error messages

Installation bashdotnet add package MingoLib.ClientFactory Configuration Register the service handler in your dependency injection container: csharp// Program.cs or Startup.cs services.AddHttpClient(); // Required for IHttpClientFactory services.AddSingleton(new ServiceConfig { BaseUrl = "https://api.example.com" }); services.AddScoped<IServiceHandler, ServiceHandler>(); Basic Usage csharppublic class ExampleService { private readonly IServiceHandler _serviceHandler;

public ExampleService(IServiceHandler serviceHandler)
{
    _serviceHandler = serviceHandler;
}

public async Task<UserDto> GetUserAsync(int userId)
{
    return await _serviceHandler.GetEntityAsync<UserDto>($"users/{userId}");
}

public async Task<UserDto> CreateUserAsync(CreateUserRequest request)
{
    return await _serviceHandler.CreateEntityAsync<UserDto, CreateUserRequest>(
        request, "users");
}

} Response Models The library includes structured response models to standardize API responses: csharp// Success response with data var successResponse = await _serviceHandler.GetAsync<ResponseModel<ApiCodes, UserDto>>("users/123"); if (successResponse.IsSuccessful) { UserDto user = successResponse.Data; // Process user data... }

// Handle failure try { var response = await _serviceHandler.GetAsync<ResponseModel<ApiCodes, UserDto>>("users/999"); if (!response.IsSuccessful) { // Handle standard error response using Code and Message logger.LogWarning("API error: {Code} - {Message}", response.Code, response.Message); } } catch (ServiceException ex) { // Create custom error response with detailed message var errorResponse = ResponseModel<ApiCodes, UserDto>.Failure( ApiCodes.NotFound, $"User with ID 999 was not found. Details: {ex.Message}");

// Or with validation errors
var errorDict = new Dictionary<string, string[]> 
{
    { "id", new[] { "Invalid user ID format" } }
};
var validationResponse = ResponseErrorModel<ApiCodes>.Failure(
    ApiCodes.ValidationError,
    "The user ID provided was invalid or malformed",
    errorDict);

} Available Methods GET Requests csharp// Simple GET var user = await _serviceHandler.GetEntityAsync<UserDto>("users/123");

// GET with body var searchResult = await _serviceHandler.GetEntityWithBodyAsync<SearchResultDto, SearchRequest>( searchRequest, "search"); POST Requests csharp// JSON POST var newUser = await _serviceHandler.CreateEntityAsync<UserDto, CreateUserRequest>( createRequest, "users");

// Form POST var formData = new Dictionary<string, string> { { "username", "johndoe" }, { "password", "securepassword" } }; var loginResult = await _serviceHandler.PostFormAsync<LoginResultDto>(formData, "auth/login");

// POST without body var result = await _serviceHandler.PostEntityAsync<ResultDto>("endpoint"); PUT Requests csharp// Update an entity var updatedUser = await _serviceHandler.UpdateEntityAsync<UserDto, UpdateUserRequest>( updateRequest, $"users/{userId}"); PATCH Requests csharp// Partial update var patchedUser = await _serviceHandler.PatchEntityAsync<UserDto, PatchUserRequest>( patchRequest, $"users/{userId}"); DELETE Requests csharp// Simple delete (returns success/failure) bool success = await _serviceHandler.DeleteEntityAsync($"users/{userId}");

// Delete with response var deletionResult = await _serviceHandler.DeleteEntityWithResponseAsync<DeletionResultDto>( $"users/{userId}");

// Delete with request body var bulkDeleteResult = await _serviceHandler.DeleteEntityWithBodyAsync<BulkDeleteResultDto, BulkDeleteRequest>( bulkDeleteRequest, "users/bulk-delete"); Error Handling The library provides a custom ServiceException that includes:

The original HTTP response Raw response content HTTP status code

csharptry { var user = await _serviceHandler.GetEntityAsync<UserDto>("users/123"); } catch (ServiceException ex) { Console.WriteLine($"Request failed with status code: {ex.StatusCode}"); Console.WriteLine($"Response content: {ex.ResponseContent}");

// Create a custom failure response with context-specific message
var errorResponse = ResponseModel<ApiCodes, UserDto>.Failure(
    ApiCodes.ServerError,
    $"Server error occurred while fetching user data: {ex.Message}");
    
// Log the error with the custom message
logger.LogError("API error: {Code} - {Message}", errorResponse.Code, errorResponse.Message);

} Custom Error Messages You can create failure responses with custom error messages instead of using predefined enum messages: csharp// Standard failure with message from enum var standardError = ResponseModel<ApiCodes>.Failure(ApiCodes.NotFound);

// Failure with custom message var customError = ResponseModel<ApiCodes>.Failure( ApiCodes.NotFound, "The requested resource could not be found on the server" );

// Error with validation details var errors = new Dictionary<string, string[]> { { "email", new[] { "Invalid email format", "Email is required" } }, { "password", new[] { "Password must be at least 8 characters" } } };

var validationError = ResponseErrorModel<ApiCodes>.Failure( ApiCodes.ValidationError, "Please correct the validation errors and try again", errors ); Advanced Usage Custom Headers csharpvar headers = new Dictionary<string, string> { { "Authorization", $"Bearer {token}" }, { "X-Custom-Header", "CustomValue" } };

var result = await _serviceHandler.GetEntityAsync<DataDto>("data", headers); Force Success Status Code Set allowOnlySuccess = true to automatically throw an exception for non-2xx status codes: csharp// This will throw a ServiceException if the status code is not 2xx var result = await _serviceHandler.GetEntityAsync<DataDto>("data", allowOnlySuccess: true); License [Your license information here]

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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
1.13.0 622 5/10/2025
1.12.0 220 3/26/2025
1.11.0 160 3/20/2025
1.10.0 156 3/20/2025
1.0.9 508 2/12/2025
1.0.8 129 2/11/2025
1.0.7 187 12/28/2024
1.0.6 123 12/14/2024
1.0.5 117 12/14/2024
1.0.4 110 12/14/2024
1.0.3 118 12/14/2024
1.0.2 104 12/14/2024
1.0.1 110 12/10/2024
1.0.0 104 12/10/2024