Linger.HttpClient.Contracts
0.8.2-preview
See the version list below for details.
dotnet add package Linger.HttpClient.Contracts --version 0.8.2-preview
NuGet\Install-Package Linger.HttpClient.Contracts -Version 0.8.2-preview
<PackageReference Include="Linger.HttpClient.Contracts" Version="0.8.2-preview" />
<PackageVersion Include="Linger.HttpClient.Contracts" Version="0.8.2-preview" />
<PackageReference Include="Linger.HttpClient.Contracts" />
paket add Linger.HttpClient.Contracts --version 0.8.2-preview
#r "nuget: Linger.HttpClient.Contracts, 0.8.2-preview"
#:package Linger.HttpClient.Contracts@0.8.2-preview
#addin nuget:?package=Linger.HttpClient.Contracts&version=0.8.2-preview&prerelease
#tool nuget:?package=Linger.HttpClient.Contracts&version=0.8.2-preview&prerelease
Linger.HttpClient.Contracts
Table of Contents
- Overview
- Features
- Installation
- ApiResult and Linger.Results Integration
- Quick Start
- Best Practices
- Related Documentation
Overview
Linger.HttpClient.Contracts defines standard interfaces and contracts for HTTP client operations, enabling dependency inversion and implementation flexibility.
๐ฏ Core Benefits
- Decouple - Separate business logic from HTTP implementations
- Switch - Seamlessly change HTTP client implementations
- Test - Easy unit testing with mock implementations
- Extend - Support custom HTTP client implementations
๐๏ธ Architecture Layers
Application โ IHttpClient Interface โ Concrete Implementation
(Contracts) (Standard/Custom)
Features
- Strongly Typed Contracts: Generic
ApiResult<T>for type-safe responses - Async Support: Full async/await pattern with
CancellationToken - Error Handling: Structured
ApiResulterror handling framework - Dependency Injection: Designed for DI containers and HttpClientFactory
- Extensibility: Easy to implement custom HTTP clients
Installation
# Core contracts
dotnet add package Linger.HttpClient.Contracts
# Production implementation
dotnet add package Linger.HttpClient.Standard
ApiResult and Linger.Results Integration
ApiResult is designed to seamlessly integrate with Linger.Results, but also fully compatible with other API designs:
When integrated with Linger.Results:
- Error Structure Compatibility -
ApiResult.ErrorsmatchesResult<T>.Errorsstructure - Status Code Mapping - HTTP status automatically corresponds to Result error types
- Message Propagation - Server-side error information fully transmitted to client
When integrated with other APIs:
- Standard HTTP Responses - Automatically parses HTTP status codes and response bodies
- Flexible Error Handling - Supports arbitrary JSON error formats
- Universal Adaptation - Works with REST, GraphQL, and various API styles
๐ก Detailed Integration Examples: See StandardHttpClient Documentation
Quick Start
๐ Basic Usage
// 1. Register implementation
services.AddHttpClient<IHttpClient, StandardHttpClient>();
// 2. Inject and use
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;
}
}
๐ Implementation Switching
// Development: Standard implementation
services.AddHttpClient<IHttpClient, StandardHttpClient>();
// Testing: Mock implementation
services.AddSingleton<IHttpClient, MockHttpClient>();
// Production: Resilient implementation
services.AddHttpClient<IHttpClient, ResilientHttpClient>();
Best Practices
๐๏ธ Architecture Principles
- Always program against interfaces - Use
IHttpClient, never concrete implementations - Register implementations in DI - Let the container manage lifecycle and dependencies
- Keep business logic implementation-agnostic - Your services should work with any IHttpClient implementation
๐งช Testing Strategy
- Interface mocking - Use mock implementations for unit tests
- Integration testing - Use real implementations to verify HTTP behavior
- Error testing - Ensure graceful handling of network exceptions
๐ Performance Considerations
- Resource management - Properly implement IDisposable
- Async patterns - Use ConfigureAwait(false)
- Cancellation support - Respect CancellationToken
๐ Related Documentation
- StandardHttpClient - Production implementation with detailed usage examples
| 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 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. |
| .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. |
-
.NETFramework 4.7.2
- Linger.Utils (>= 0.8.2-preview)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.0
- Linger.Utils (>= 0.8.2-preview)
-
net8.0
- Linger.Utils (>= 0.8.2-preview)
-
net9.0
- Linger.Utils (>= 0.8.2-preview)
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 | 155 | 10/14/2025 |
| 0.9.7-preview | 146 | 10/13/2025 |
| 0.9.6-preview | 127 | 10/12/2025 |
| 0.9.5 | 141 | 9/28/2025 |
| 0.9.4-preview | 163 | 9/25/2025 |
| 0.9.3-preview | 203 | 9/22/2025 |
| 0.9.1-preview | 293 | 9/16/2025 |
| 0.9.0-preview | 122 | 9/12/2025 |
| 0.8.5-preview | 221 | 8/31/2025 |
| 0.8.4-preview | 340 | 8/25/2025 |
| 0.8.3-preview | 200 | 8/20/2025 |
| 0.8.2-preview | 230 | 8/4/2025 |
| 0.8.1-preview | 133 | 7/30/2025 |
| 0.8.0-preview | 591 | 7/22/2025 |
| 0.7.2 | 211 | 6/3/2025 |
| 0.7.1 | 217 | 5/21/2025 |
| 0.7.0 | 211 | 5/19/2025 |
| 0.6.0-alpha | 217 | 4/28/2025 |
| 0.5.0-alpha | 218 | 4/10/2025 |
| 0.4.0-alpha | 193 | 4/1/2025 |