Tolitech.HttpClients
1.0.0-preview.2
dotnet add package Tolitech.HttpClients --version 1.0.0-preview.2
NuGet\Install-Package Tolitech.HttpClients -Version 1.0.0-preview.2
<PackageReference Include="Tolitech.HttpClients" Version="1.0.0-preview.2" />
paket add Tolitech.HttpClients --version 1.0.0-preview.2
#r "nuget: Tolitech.HttpClients, 1.0.0-preview.2"
// Install Tolitech.HttpClients as a Cake Addin #addin nuget:?package=Tolitech.HttpClients&version=1.0.0-preview.2&prerelease // Install Tolitech.HttpClients as a Cake Tool #tool nuget:?package=Tolitech.HttpClients&version=1.0.0-preview.2&prerelease
Tolitech.HttpClients.Abstractions
Tolitech.HttpClients.Abstractions provides contracts and abstractions to facilitate the creation of HTTP clients. It defines the necessary interfaces to build and consume HTTP APIs in a consistent and extensible way.
Features
- Defines fundamental interfaces for HTTP operations:
IHttpClient
: Marks classes that represent HTTP clients.IRequest
: Base contract for request objects sent to an HTTP endpoint.IResponse
: Base contract for response objects received from an HTTP endpoint.
Purpose
This project serves as a foundation for standardizing HTTP communication in applications, allowing simplified integration with concrete implementations of HTTP clients.
Usage
Implement the provided interfaces to create custom request and response structures. A simple example:
public class MyRequest : IRequest
{
public string Name { get; set; }
}
public class MyResponse : IResponse
{
public string Message { get; set; }
}
Tolitech.HttpClients
Tolitech.HttpClients is a practical implementation of an HTTP client based on the abstractions provided by Tolitech.HttpClients.Abstractions. This project contains the base class BaseHttpClient
, which offers methods for performing HTTP operations such as GET, POST, PUT, PATCH, and DELETE.
Features
- Generic implementation for HTTP clients.
- Built-in support for JSON requests and responses.
- Header management and response validation.
- Direct integration with the contracts from
Tolitech.HttpClients.Abstractions
.
Main Class
BaseHttpClient
BaseHttpClient
provides methods such as:
GetAsync<TResponse>()
: Performs an HTTP GET request.PostAsync<TRequest, TResponse>()
: Performs an HTTP POST request.PutAsync<TRequest, TResponse>()
: Performs an HTTP PUT request.PatchAsync<TRequest, TResponse>()
: Performs an HTTP PATCH request.DeleteAsync<TResponse>()
: Performs an HTTP DELETE request.
Example Usage
public class MyHttpClient : BaseHttpClient
{
public MyHttpClient(HttpClient httpClient) : base(httpClient) { }
public async Task<Result<MyResponse>> GetMessageAsync(string url)
{
return await GetAsync<MyResponse>(url);
}
}
How to Use
HttpClient client = new HttpClient();
var service = new MyHttpClient(client);
var result = await service.GetMessageAsync("https://api.example.com/message");
if (result.IsSuccess)
{
Console.WriteLine(result.Value.Message);
}
else
{
Console.WriteLine($"Error: {result.Detail}");
}
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
- Tolitech.HttpClients.Abstractions (>= 1.0.0-preview.1)
- Tolitech.Results (>= 1.0.0-preview.1)
- Tolitech.Results.Http (>= 1.0.0-preview.1)
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-preview.2 | 40 | 2/17/2025 |
1.0.0-preview.1 | 9 | 1/29/2025 |