Linger.HttpClient.Standard 0.5.0-alpha

This is a prerelease version of Linger.HttpClient.Standard.
dotnet add package Linger.HttpClient.Standard --version 0.5.0-alpha
                    
NuGet\Install-Package Linger.HttpClient.Standard -Version 0.5.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.5.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.5.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.5.0-alpha
                    
#r "nuget: Linger.HttpClient.Standard, 0.5.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.
#addin nuget:?package=Linger.HttpClient.Standard&version=0.5.0-alpha&prerelease
                    
Install Linger.HttpClient.Standard as a Cake Addin
#tool nuget:?package=Linger.HttpClient.Standard&version=0.5.0-alpha&prerelease
                    
Install Linger.HttpClient.Standard 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.

Core Advantages

  • Lightweight Design: Minimal dependencies, low runtime overhead
  • .NET Integration: Seamlessly works with HttpClientFactory and DI
  • High Performance: Optimized for performance in .NET environments
  • Easy Configuration: Simple setup with familiar .NET patterns

Installation

dotnet add package Linger.HttpClient.Standard

Quick Start

Basic Creation

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

// Configure options
client.Options.DefaultTimeout = 30;
client.Options.EnableRetry = true;
client.AddHeader("User-Agent", "Linger.Client");

With HttpClientFactory

// In your startup configuration
services.AddHttpClient<StandardHttpClient>(client =>
{
    client.BaseAddress = new Uri("https://api.example.com/");
    client.DefaultRequestHeaders.Add("Accept", "application/json");
})
.AddTypedClient<IHttpClient>((httpClient, serviceProvider) => 
{
    var standardClient = new StandardHttpClient(httpClient);
    
    // Configure options
    standardClient.Options.EnableRetry = true;
    standardClient.Options.MaxRetryCount = 3;
    
    return standardClient;
});

Usage Examples

Simple GET Request

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

// Process response
if (response.IsSuccess)
{
    Console.WriteLine($"User: {response.Data.Name}");
}

POST Request with JSON

// Create user data
var userData = new UserCreateModel { Name = "John", Email = "john@example.com" };

// Send POST request
var response = await client.CallApi<UserData>(
    "api/users",
    HttpMethodEnum.Post,
    userData
);

File Upload

// Read file
byte[] fileData = File.ReadAllBytes("document.pdf");

// Create form data
var formData = new Dictionary<string, string>
{
    { "description", "Sample document" }
};

// Upload file
var response = await client.CallApi<FileResponse>(
    "api/files",
    HttpMethodEnum.Post,
    formData,
    fileData,
    "document.pdf"
);

Best Practices

Configuration

// Recommended settings for production
client.Options.DefaultTimeout = 15; // 15 seconds timeout
client.Options.EnableRetry = true;
client.Options.MaxRetryCount = 3;
client.Options.RetryInterval = 1000; // 1 second between retries

Error Handling

try
{
    var response = await client.CallApi<UserData>("api/users/1");
    
    if (response.IsSuccess)
    {
        // Process data
    }
    else
    {
        // Handle API error
        Console.WriteLine($"API Error: {response.ErrorMsg}");
    }
}
catch (Exception ex)
{
    // Handle network or other exceptions
    Console.WriteLine($"Request failed: {ex.Message}");
}

Resource Management

When using StandardHttpClient directly (not via HttpClientFactory), dispose it properly when finished:

using (var httpClient = new System.Net.Http.HttpClient())
{
    var client = new StandardHttpClient(httpClient);
    // Use client...
}

When using HttpClientFactory, disposal is handled automatically.

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. 
.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

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.5.0-alpha 116 4/10/2025
0.4.0-alpha 112 4/1/2025