Linger.HttpClient.Contracts 0.8.2-preview

This is a prerelease version of Linger.HttpClient.Contracts.
There is a newer version of this package available.
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
                    
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.8.2-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.HttpClient.Contracts" Version="0.8.2-preview" />
                    
Directory.Packages.props
<PackageReference Include="Linger.HttpClient.Contracts" />
                    
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 Linger.HttpClient.Contracts --version 0.8.2-preview
                    
#r "nuget: Linger.HttpClient.Contracts, 0.8.2-preview"
                    
#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.8.2-preview
                    
#: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.8.2-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Linger.HttpClient.Contracts&version=0.8.2-preview&prerelease
                    
Install as a Cake Tool

Linger.HttpClient.Contracts

Table of Contents

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 ApiResult error 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.Errors matches Result<T>.Errors structure
  • 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

  1. Always program against interfaces - Use IHttpClient, never concrete implementations
  2. Register implementations in DI - Let the container manage lifecycle and dependencies
  3. Keep business logic implementation-agnostic - Your services should work with any IHttpClient implementation

๐Ÿงช Testing Strategy

  1. Interface mocking - Use mock implementations for unit tests
  2. Integration testing - Use real implementations to verify HTTP behavior
  3. Error testing - Ensure graceful handling of network exceptions

๐Ÿ“Š Performance Considerations

  1. Resource management - Properly implement IDisposable
  2. Async patterns - Use ConfigureAwait(false)
  3. Cancellation support - Respect CancellationToken

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

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