Generic-Http-Client
1.0.0
dotnet add package Generic-Http-Client --version 1.0.0
NuGet\Install-Package Generic-Http-Client -Version 1.0.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="Generic-Http-Client" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Generic-Http-Client" Version="1.0.0" />
<PackageReference Include="Generic-Http-Client" />
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 Generic-Http-Client --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Generic-Http-Client, 1.0.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 Generic-Http-Client@1.0.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=Generic-Http-Client&version=1.0.0
#tool nuget:?package=Generic-Http-Client&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Generic HTTP Client
GenericHttpClient is a library that provides a simple and flexible way to send HTTP requests using a generic HTTP client. It supports GET, POST, PUT, and DELETE requests and handles responses with built-in deserialization.
Features
- Generic HTTP client interface for easy integration
- Support for GET, POST, PUT, and DELETE requests
- Automatic deserialization of JSON responses
- Detailed error handling and response status
Installation
You can install the GenericHttpClient NuGet package using the .NET CLI:
dotnet add package GenericHttpClient
Or via the NuGet Package Manager:
Install-Package GenericHttpClient
Usage
1. Create an instance of HttpClientWrapper
var httpClientWrapper = new HttpClientWrapper();
2. Create an instance of GenericHttpClient
var genericHttpClient = new GenericHttpClient(httpClientWrapper);
3. Send a request
var url = "https://api.example.com/data";
var response = await genericHttpClient.SendRequestAsync<MyResponseType>(url, HttpRequestType.GET);
if (response.ResponseType == HttpResponseType.Success)
{
var data = response.Data;
// Handle success
}
else
{
// Handle failure
Console.WriteLine(response.Message);
}
Classes and Interfaces
GenericHttpClient
| Method | Description |
|---|---|
| SendRequestAsync<T>(url, httpRequestType, payload) | Sends a request of the specified type to the provided URL with an optional payload. |
HttpClientWrapper
| Method | Description |
|---|---|
| GetAsync(url) | Sends a GET request to the specified URL. |
| PostAsync<T>(url, payload) | Sends a POST request with the provided payload to the specified URL. |
| PutAsync<T>(url, payload) | Sends a PUT request with the provided payload to the specified URL. |
| DeleteAsync(url) | Sends a DELETE request to the specified URL. |
HttpResponse<T>
| Property | Description |
|---|---|
| ResponseType | Indicates the type of response (Success, Failure, etc.) |
| Message | Provides a message in case of failure or empty response |
| Data | Contains the deserialized data from the response |
HttpRequestType
| Value | Description |
|---|---|
| GET | GET request |
| POST | POST request |
| PUT | PUT request |
| DELETE | DELETE request |
HttpResponseType
| Value | Description |
|---|---|
| Success | The request was successful and the response contains data. |
| Failure | The request failed. |
| Empty | The request succeeded but the response was empty. |
| Undeserializable | The request succeeded but the response could not be deserialized. |
Example
Here's an example of sending a POST request with a payload:
var url = "https://api.example.com/data";
var payload = new MyRequestType { Property1 = "value1", Property2 = "value2" };
var response = await genericHttpClient.SendRequestAsync<MyResponseType>(url, HttpRequestType.POST, payload);
if (response.ResponseType == HttpResponseType.Success)
{
var data = response.Data;
// Handle success
}
else
{
// Handle failure
Console.WriteLine(response.Message);
}
License
This project is licensed under the MIT License.
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
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.0.0 | 177 | 5/26/2024 |