Linger.HttpClient.Contracts
0.9.8
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.7.2
This package targets .NET Framework 4.7.2. The package is compatible with this framework or higher.
dotnet add package Linger.HttpClient.Contracts --version 0.9.8
NuGet\Install-Package Linger.HttpClient.Contracts -Version 0.9.8
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="Linger.HttpClient.Contracts" Version="0.9.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.HttpClient.Contracts" Version="0.9.8" />
<PackageReference Include="Linger.HttpClient.Contracts" />
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 Linger.HttpClient.Contracts --version 0.9.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Linger.HttpClient.Contracts, 0.9.8"
#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 Linger.HttpClient.Contracts@0.9.8
#: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=Linger.HttpClient.Contracts&version=0.9.8
#tool nuget:?package=Linger.HttpClient.Contracts&version=0.9.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Linger.HttpClient.Contracts
中文 | English
Standard interfaces and contracts for HTTP client operations.
Features
- Interface Decoupling: Separate business logic from HTTP implementations
- Implementation Flexibility: Support multiple HTTP client implementations
- Testing Friendly: Easy unit testing and mocking
- Strongly Typed: Generic
ApiResult<T>for type safety - Async Support: Full async/await pattern
Installation
# Core contracts
dotnet add package Linger.HttpClient.Contracts
# Production implementation
dotnet add package Linger.HttpClient.Standard
Core Interfaces
IHttpClient
public interface IHttpClient : IDisposable
{
Task<ApiResult<T>> CallApi<T>(string url, HttpMethodEnum method = HttpMethodEnum.Get,
object? data = null, Dictionary<string, string>? headers = null,
Dictionary<string, object>? queryParams = null, CancellationToken cancellationToken = default);
}
ApiResult<T>
public class ApiResult<T>
{
public bool IsSuccess { get; set; }
public T Data { get; set; }
public string ErrorMsg { get; set; }
public HttpStatusCode StatusCode { get; set; }
public Error[] Errors { get; set; }
}
Basic Usage
// Register in DI
services.AddHttpClient<IHttpClient, StandardHttpClient>();
// Use in service
public class UserService
{
private readonly IHttpClient _httpClient;
public UserService(IHttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<User?> GetUserAsync(int id)
{
var result = await _httpClient.CallApi<User>($"api/users/{id}");
return result.IsSuccess ? result.Data : null;
}
}
Linger.Results Integration
ApiResult seamlessly integrates with Linger.Results:
// Server using Linger.Results
public async Task<Result<User>> GetUserAsync(int id)
{
var user = await _userRepository.GetUserAsync(id);
return user is not null ? Result<User>.Success(user) : Result<User>.NotFound("User not found");
}
// Client receives structured errors
var apiResult = await _httpClient.CallApi<User>($"api/users/{id}");
if (!apiResult.IsSuccess)
{
// Automatically mapped error information
foreach (var error in apiResult.Errors)
Console.WriteLine($"Error: {error.Code} - {error.Message}");
}
Error Handling
var result = await _httpClient.CallApi<User>("api/users/123");
if (result.IsSuccess)
{
var user = result.Data;
// Handle success
}
else
{
// Handle error
Console.WriteLine($"HTTP Status: {result.StatusCode}");
Console.WriteLine($"Error Message: {result.ErrorMsg}");
foreach (var error in result.Errors)
{
Console.WriteLine($"Detailed Error: {error.Code} - {error.Message}");
}
}
Best Practices
- Use dependency injection to manage HTTP client lifecycle
- Leverage
ApiResult's structured error handling - Inherit from existing implementations when implementing custom error handling
- Use
CancellationTokento support request cancellation - Use mock implementations in unit tests
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 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 is compatible. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.7.2
- Linger.Utils (>= 0.9.8)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.0
- Linger.Utils (>= 0.9.8)
-
net10.0
- Linger.Utils (>= 0.9.8)
-
net8.0
- Linger.Utils (>= 0.9.8)
-
net9.0
- Linger.Utils (>= 0.9.8)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Linger.HttpClient.Contracts:
| Package | Downloads |
|---|---|
|
Linger.HttpClient.Standard
A lightweight implementation of Linger.HttpClient.Contracts using standard .NET HttpClient. Provides robust HTTP request handling with automatic retries, timeout management, and typed response parsing. Seamlessly integrates with .NET's HttpClientFactory for optimal connection management. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.9.8 | 151 | 10/14/2025 |
| 0.9.7-preview | 143 | 10/13/2025 |
| 0.9.6-preview | 125 | 10/12/2025 |
| 0.9.5 | 138 | 9/28/2025 |
| 0.9.4-preview | 160 | 9/25/2025 |
| 0.9.3-preview | 201 | 9/22/2025 |
| 0.9.1-preview | 290 | 9/16/2025 |
| 0.9.0-preview | 120 | 9/12/2025 |
| 0.8.5-preview | 220 | 8/31/2025 |
| 0.8.4-preview | 339 | 8/25/2025 |
| 0.8.3-preview | 199 | 8/20/2025 |
| 0.8.2-preview | 229 | 8/4/2025 |
| 0.8.1-preview | 132 | 7/30/2025 |
| 0.8.0-preview | 590 | 7/22/2025 |
| 0.7.2 | 210 | 6/3/2025 |
| 0.7.1 | 216 | 5/21/2025 |
| 0.7.0 | 209 | 5/19/2025 |
| 0.6.0-alpha | 216 | 4/28/2025 |
| 0.5.0-alpha | 217 | 4/10/2025 |
| 0.4.0-alpha | 192 | 4/1/2025 |