HttpLight.NET
1.0.0
dotnet add package HttpLight.NET --version 1.0.0
NuGet\Install-Package HttpLight.NET -Version 1.0.0
<PackageReference Include="HttpLight.NET" Version="1.0.0" />
paket add HttpLight.NET --version 1.0.0
#r "nuget: HttpLight.NET, 1.0.0"
// Install HttpLight.NET as a Cake Addin #addin nuget:?package=HttpLight.NET&version=1.0.0 // Install HttpLight.NET as a Cake Tool #tool nuget:?package=HttpLight.NET&version=1.0.0
HttpLight
HttpLight is a lightweight and efficient HTTP client for .NET, designed to simplify HTTP requests with built-in response conversion and retry logic.
Unlike HttpClient
, it reduces boilerplate code and enhances reliability with automatic retries and customizable delays.
Supporting both synchronous and asynchronous methods, HttpLight ensures flexibility while maintaining performance.
It provides seamless handling for GET, POST, PUT, DELETE, and multipart form data requests, making API integration effortless.
With its minimalistic design, low memory consumption, and high efficiency, HttpLight is the perfect choice for developers looking for a simple yet powerful HTTP client.
Documentation
Additional:
Dispose()
- Releases unmanaged resources and disposes the internalHttpClient
.SetDefaultHeaders()
- Sets default headers for the HTTP client.RemoveDefaultHeaders()
- Removes all default headers from the HTTP client.SetTimeout()
- Sets the timeout for the HTTP client.RemoveTimeout()
- Removes the timeout from the HTTP client.SetBearerToken()
- Sets the bearer token for the HTTP client.RemoveAuthorizationHeader()
- Removes the bearer token from the HTTP client.Send()
- Sends a synchronous HTTP request using the specifiedHttpRequestMessage
and returns the response deserialized to the specified type.SendAsync()
- Sends aa asynchronous HTTP request using the specifiedHttpRequestMessage
and returns the response deserialized to the specified type.
GET methods:
Get()
- Synchronously executes a GET request.GetAsync()
- Asynchronously performs a GET request.GetWithRetry()
- Synchronously performs the specified number of attempts to send a GET request with the specified delay between each attempt.GetWithRetryAsync()
- Asynchronously performs the specified number of attempts to send a GET request with the specified delay between each attempt.
POST methods:
Post()
- Synchronously executes a POST request.PostAsync()
- Asynchronously executes a POST request.PostWithRetry()
- Synchronously performs the specified number of attempts to send a POST request with the specified delay between each attempt.PostWithRetryAsync()
- Asynchronously performs the specified number of attempts to send a GET request with the specified delay between each attempt.PostFormData()
- Sends a synchronous HTTP POST request with multipart/form-data content and returns the response deserialized to the specified type.PostFormDataAsync()
- Sends an asynchronous HTTP POST request with multipart/form-data content and returns the response deserialized to the specified type.
PUT methods:
Put()
- Synchronously executes a PUT request.PutAsync()
- Asynchronously executes a PUT request.PutWithRetry()
- Synchronously performs the specified number of attempts to send a PUT request with the specified delay between each attempt.PutWithRetryAsync()
- Asynchronously performs the specified number of attempts to send a PUT request with the specified delay between each attempt.PutFormData()
- Sends a synchronous HTTP PUT request with multipart/form-data content and returns the response deserialized to the specified type.PutFormDataAsync()
- Sends an asynchronous HTTP PUT request with multipart/form-data content and returns the response deserialized to the specified type.
PATCH methods:
Patch()
- Synchronously executes a PATCH request.PatchAsync()
- Asynchronously executes a PATCH request.PatchWithRetry()
- Synchronously performs the specified number of attempts to send a PATCH request with the specified delay between each attempt.PatchWithRetryAsync()
- Asynchronously performs the specified number of attempts to send a PUT request with the specified delay between each attempt.PatchFormData()
- Sends a synchronous HTTP PATCH request with multipart/form-data content and returns the response deserialized to the specified type.PatchFormDataAsync()
- Sends an asynchronous HTTP PATCH request with multipart/form-data content and returns the response deserialized to the specified type.
DELETE methods:
Delete()
- Sends a synchronous HTTP DELETE request to the specified URL and returns the response deserialized to the specified type.DeleteAsync()
- Sends an asynchronous HTTP DELETE request to the specified URL and returns the response deserialized to the specified type.DeleteWithRetry()
- Sends a synchronous HTTP DELETE request to the specified URL with retry logic, and returns the response deserialized to the specified type.DeleteWithRetryAsync()
- Sends an asynchronous HTTP DELETE request to the specified URL with retry logic, and returns the response deserialized to the specified type.
Usage
To use the library functionality, you need to initialize the HttpLight
object:
var httpLight = new HttpLight();
Below is an example of sending a GET request:
var response = httpLight.Get<OutputModel>("https://jsonplaceholder.typicode.com/posts/1");
Console.WriteLine(response.Body);
Below is an example of sending a POST request:
var request = new OutputModel
{
UserId = 1,
Title = "title",
Body = "body"
};
var json = JsonConvert.SerializeObject(request);
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
var response = httpLight.Post<OutputModel>("https://jsonplaceholder.typicode.com/posts", content);
Console.WriteLine(response.Title);
Installation
To install the package, use the following command:
dotnet add package HttpLight
or via NuGet Package Manager:
Install-Package HttpLight
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net9.0
- Newtonsoft.Json (>= 13.0.3)
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 | 72 | 1/31/2025 |