YouBIM.Common.HttpClient.Lib
9.0.6
See the version list below for details.
dotnet add package YouBIM.Common.HttpClient.Lib --version 9.0.6
NuGet\Install-Package YouBIM.Common.HttpClient.Lib -Version 9.0.6
<PackageReference Include="YouBIM.Common.HttpClient.Lib" Version="9.0.6" />
<PackageVersion Include="YouBIM.Common.HttpClient.Lib" Version="9.0.6" />
<PackageReference Include="YouBIM.Common.HttpClient.Lib" />
paket add YouBIM.Common.HttpClient.Lib --version 9.0.6
#r "nuget: YouBIM.Common.HttpClient.Lib, 9.0.6"
#:package YouBIM.Common.HttpClient.Lib@9.0.6
#addin nuget:?package=YouBIM.Common.HttpClient.Lib&version=9.0.6
#tool nuget:?package=YouBIM.Common.HttpClient.Lib&version=9.0.6
YouBIM.Common.HttpClient.Lib
Overview
YouBIM.Common.HttpClient.Lib is a helper library designed to simplify HTTP client operations in .NET applications. It abstracts the complexities of sending HTTP requests and handling responses, providing a consistent interface for GET, POST, PUT, PATCH, and DELETE operations. The library supports custom headers for different microservice types and includes built-in logging for improved traceability.
Features
- Support for GET, POST, PUT, PATCH, and DELETE HTTP methods.
- Configurable to handle requests for different microservice types (e.g., PHP and .NET).
- Automatic inclusion of authorization headers.
- Integrated error handling and logging.
- JSON serialization/deserialization for seamless data handling.
Installation
Include the YouBIM.Common.HttpClient.Lib DLL in your .NET project by adding it as a reference or using a package manager (if available as a NuGet package).
dotnet add package YouBIM.Common.HttpClient.Lib
Usage
Initialization
To use the HttpClientHelper, ensure that IHttpClientFactory, IUserContextService, and ILogger are properly configured in your application:
services.AddHttpClient();
services.AddScoped<IHttpClientHelper, HttpClientHelper>();
Example Code
GET Request
var result = await httpClientHelper.GetAsync<MyResponseType>("https://api.example.com/data");
POST Request
var data = new MyRequestData { Property = "Value" };
var response = await httpClientHelper.PostAsync<MyResponseType, MyRequestData>("https://api.example.com/data", data);
PUT Request
var updateData = new MyUpdateData { Property = "UpdatedValue" };
var updatedResponse = await httpClientHelper.PutAsync<MyResponseType, MyUpdateData>("https://api.example.com/data/1", updateData);
PATCH Request
var patchData = new MyPatchData { Property = "PatchedValue" };
var patchedResponse = await httpClientHelper.PatchAsync<MyResponseType, MyPatchData>("https://api.example.com/data/1", patchData);
DELETE Request
var deleteResponse = await httpClientHelper.DeleteAsync<MyResponseType>("https://api.example.com/data/1");
Configuration
The library differentiates between microservice types using the MicroserviceType enum:
PHP: Uses theX-AUTH-TOKENheader.DotNet: Uses theBearertoken for theAuthorizationheader.
Error Handling
The HttpClientHelper handles common exceptions, such as HttpRequestException and TaskCanceledException, and logs detailed information for debugging purposes.
Contributing
Feel free to contribute by opening issues or submitting pull requests.
License
This project is licensed under the MIT License.
Contact
For questions or support, please contact support@youbim.com.
| Product | Versions 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. |
-
net8.0
- Microsoft.Extensions.Http (>= 9.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.