HTTPClientServiceEx 1.9.0

Suggested Alternatives

SmartHttpClient

Additional Details

The HttpClientService package is now deprecated and is no longer maintained. We strongly recommend migrating to the new SmartHttpClient package (version 1.0.0), which offers enhanced features, improved performance, and better support for modern HTTP client use cases.

SmartHttpClient simplifies HTTP interactions by automatically handling JSON serialization/deserialization, managing authentication, and providing a clean, reusable API. It's designed to save developers time and effort while ensuring best practices.

To migrate, update your project references with the SmartHttpClient package:
dotnet add package SmartHttpClient --version 1.0.0

dotnet add package HTTPClientServiceEx --version 1.9.0
                    
NuGet\Install-Package HTTPClientServiceEx -Version 1.9.0
                    
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="HTTPClientServiceEx" Version="1.9.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HTTPClientServiceEx" Version="1.9.0" />
                    
Directory.Packages.props
<PackageReference Include="HTTPClientServiceEx" />
                    
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 HTTPClientServiceEx --version 1.9.0
                    
#r "nuget: HTTPClientServiceEx, 1.9.0"
                    
#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 HTTPClientServiceEx@1.9.0
                    
#: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=HTTPClientServiceEx&version=1.9.0
                    
Install as a Cake Addin
#tool nuget:?package=HTTPClientServiceEx&version=1.9.0
                    
Install as a Cake Tool

HTTPClientServiceEx

HTTPClientServiceEx is a library for .NET 8.0 that simplifies the use of HttpClient. It provides a reusable, configurable, and extendable way to interact with external APIs or HTTP services.

Installation

Install the package via NuGet:

dotnet add package HTTPClientServiceEx --version 1.9.0

Setup To use this library, you need to register the required services in your Program.cs file.

  1. Add HTTP Client Services In the Program.cs file of your .NET project, add the following lines:

builder.Services.AddHttpClient(); builder.Services.AddTransient<IHTTPClientWrapper, HTTPClientWrapper>();

  1. Dependency Injection Example If you're using Dependency Injection in your application (e.g., in a Controller or Service), you can inject the IHTTPClientWrapper like this:

public class MyService { private readonly IHTTPClientWrapper _hTTPClientWrapper; public MyService(IHTTPClientWrapper hTTPClientWrapper) { _hTTPClientWrapper = hTTPClientWrapper; }

// Your methods here
public async Task<T> SendRequestAsync<T>(object requestParam) where T : class
{
	var request = new HTTPClientRequest()
	{
		BaseUri = new Uri($"https://localhost:7081/api/Application"),
		Method = HttpMethod.Get,
		RequestBody = new { Id = 1 },
		EndpointParams = requestParam,
		Timeout = TimeSpan.FromSeconds(5),
		Authenticator = new Authenticator() { AccessToken = "ABC", Auth = AuthenticationMethod.Bearer },
		Headers = new Dictionary<string, string>() { { "api-version", "2" } }
	};
	return = await _hTTPClientWrapper.SendAsync<T>(request);	
}

}

Dependencies Microsoft.Extensions.Http (>= 8.0.1)

Contributing Contributions are welcome! Feel free to submit a pull request or raise an issue in the GitHub repository.

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 was computed.  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. 
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
1.9.0 229 1/16/2025 1.9.0 is deprecated.

- Added new methods for HTTP GET and POST.
- Fixed bugs with retry policies.
- Improved error handling and logging.