Linger.HttpClient.Standard 0.4.0-alpha

This is a prerelease version of Linger.HttpClient.Standard.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Linger.HttpClient.Standard --version 0.4.0-alpha
                    
NuGet\Install-Package Linger.HttpClient.Standard -Version 0.4.0-alpha
                    
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.Standard" Version="0.4.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.HttpClient.Standard" Version="0.4.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Linger.HttpClient.Standard" />
                    
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.Standard --version 0.4.0-alpha
                    
#r "nuget: Linger.HttpClient.Standard, 0.4.0-alpha"
                    
#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.Standard@0.4.0-alpha
                    
#: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.Standard&version=0.4.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Linger.HttpClient.Standard&version=0.4.0-alpha&prerelease
                    
Install as a Cake Tool

Linger.HttpClient.Standard

Introduction

Linger.HttpClient.Standard is an implementation based on the standard .NET HttpClient, providing a lightweight wrapper that conforms to the Linger.HttpClient.Contracts interfaces. This project focuses on delivering a stable, efficient, and .NET-style HTTP communication solution.

🔗 This project is part of the Linger HTTP Client Ecosystem.

Core Advantages

  • Lightweight Design: Minimal dependencies, low runtime overhead
  • .NET Conventions: Naturally integrates with .NET projects, follows platform design principles
  • High Performance: Optimized for performance, suitable for high-concurrency scenarios
  • Easy Troubleshooting: Transparent implementation, clear error information
  • Low Memory Footprint: Optimized memory management, suitable for resource-constrained environments

Recent Improvements

1. Fully Integrated Interceptors

The interceptor system is now fully integrated into StandardHttpClient, ensuring consistent handling of requests and responses:

// Apply request interceptors
request = await ApplyInterceptorsToRequestAsync(request);

// Execute request
var res = await _httpClient.SendAsync(request, combinedToken);

// Apply response interceptors
res = await ApplyInterceptorsToResponseAsync(res);

2. Optimized Retry Logic

Retry logic has been moved to interceptors to avoid duplicate retries:

// Previous retry code has been removed
// var res = await ProcessRequestWithRetriesAsync(...);

// Now retries are handled uniformly by interceptors
var client = new StandardHttpClient("https://api.example.com");
client.Options.EnableRetry = true;
client.Options.MaxRetryCount = 3;

3. Automatic Benefits from StandardHttpClientFactory

When using the factory, you automatically get the benefits of interceptors and configuration:

// Create client with factory
var factory = new StandardHttpClientFactory();
var client = factory.CreateClient("https://api.example.com", options => {
    options.EnableRetry = true;
    options.DefaultTimeout = 15;
});

// Compression support and retry functionality are automatically included

Installation

dotnet add package Linger.HttpClient.Standard

Quick Start

// Create client
var client = new StandardHttpClient("https://api.example.com");

// Send request
var response = await client.GetAsync<UserData>("api/users/1");

Advanced Features

1. Custom HttpMessageHandler

Full control over the underlying HttpClient behavior:

// Custom handler
var handler = new HttpClientHandler
{
    AllowAutoRedirect = false,
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
    UseCookies = false,
    MaxConnectionsPerServer = 20
};

// Create client with custom handler
var client = new StandardHttpClient(new System.Net.Http.HttpClient(handler));

2. Integrated HTTP Compression

Use the built-in compression helper class to reduce bandwidth consumption:

// Create compression-enabled handler
var handler = CompressionHelper.CreateCompressionHandler();

// Create client
var client = new StandardHttpClient(new System.Net.Http.HttpClient(handler));

3. Efficient Parallel Requests

// Send multiple requests in parallel
var task1 = client.GetAsync<Data1>("api/endpoint1");
var task2 = client.GetAsync<Data2>("api/endpoint2");
var task3 = client.GetAsync<Data3>("api/endpoint3");

// Wait for all requests to complete
await Task.WhenAll(task1, task2, task3);

// Process all results
var result1 = task1.Result.Data;
var result2 = task2.Result.Data;
var result3 = task3.Result.Data;

Use Cases

StandardHttpClient is particularly well-suited for:

  • Performance and resource-sensitive applications: Mobile apps, applications running on low-spec devices
  • Projects requiring fine-grained HTTP communication control: Security-sensitive enterprise systems
  • Projects migrating from existing .NET HttpClient: Smooth transition, low learning curve
  • Applications requiring .NET-specific features: WinForms, WPF, or systems that need integration with .NET-specific APIs

Comparison with FlurlHttpClient

Scenario StandardHttpClient FlurlHttpClient
Performance requirements ★★★★★ ★★★☆☆
Low resource usage ★★★★★ ★★★☆☆
URL building capability ★★☆☆☆ ★★★★★
API fluency ★★★☆☆ ★★★★★
Learning curve Gentle Moderate
Suitable projects Enterprise applications, resource-constrained environments Modern web applications, complex API integrations

Best Practices

  1. Use HttpClientFactory to manage instances

    services.AddSingleton<IHttpClientFactory, StandardHttpClientFactory>();
    
  2. Create named clients grouped by API

    factory.RegisterClient("users-api", "https://users.example.com");
    factory.RegisterClient("products-api", "https://products.example.com");
    
  3. Performance-oriented configuration

    client.Options.DefaultTimeout = 15; // Shorter timeout
    
  4. Use with CancellationToken

    using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
    await client.GetAsync<Data>("api/data", cancellationToken: cts.Token);
    
  5. File Upload Best Practices

    // File uploads are now simpler, handled by MultipartHelper
    var response = await client.CallApi<UploadResult>(
        "api/upload",
        HttpMethodEnum.Post,
        formData,
        fileBytes,
        "document.pdf"
    );
    
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 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 Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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
0.9.1-preview 27 9/16/2025
0.9.0-preview 68 9/12/2025
0.8.5-preview 143 8/31/2025
0.8.4-preview 263 8/25/2025
0.8.3-preview 124 8/20/2025
0.8.2-preview 157 8/4/2025
0.8.1-preview 94 7/30/2025
0.8.0-preview 533 7/22/2025
0.7.2 154 6/3/2025
0.7.1 152 5/21/2025
0.7.0 151 5/19/2025
0.6.0-alpha 162 4/28/2025
0.5.0-alpha 157 4/10/2025
0.4.0-alpha 152 4/1/2025