Tolitech.HttpServices
1.0.0-preview.5
dotnet add package Tolitech.HttpServices --version 1.0.0-preview.5
NuGet\Install-Package Tolitech.HttpServices -Version 1.0.0-preview.5
<PackageReference Include="Tolitech.HttpServices" Version="1.0.0-preview.5" />
paket add Tolitech.HttpServices --version 1.0.0-preview.5
#r "nuget: Tolitech.HttpServices, 1.0.0-preview.5"
// Install Tolitech.HttpServices as a Cake Addin #addin nuget:?package=Tolitech.HttpServices&version=1.0.0-preview.5&prerelease // Install Tolitech.HttpServices as a Cake Tool #tool nuget:?package=Tolitech.HttpServices&version=1.0.0-preview.5&prerelease
Tolitech.HttpServices.Abstractions
Tolitech.HttpServices.Abstractions provides contracts and abstractions to facilitate the creation of HTTP services. It defines the necessary interfaces to build and consume HTTP APIs in a consistent and extensible way.
Features
- Defines fundamental interfaces for HTTP operations:
IHttpService
: Marks classes that represent HTTP services.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 services.
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.HttpServices
Tolitech.HttpServices is a practical implementation of an HTTP service based on the abstractions provided by Tolitech.HttpServices.Abstractions. This project contains the base class BaseHttpService
, which offers methods for performing HTTP operations such as GET, POST, PUT, PATCH, and DELETE.
Features
- Generic implementation for HTTP services.
- Built-in support for JSON requests and responses.
- Header management and response validation.
- Direct integration with the contracts from
Tolitech.HttpServices.Abstractions
.
Main Class
BaseHttpService
BaseHttpService
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 MyHttpService : BaseHttpService
{
public MyHttpService(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 MyHttpService(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.HttpServices.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.5 | 32 | 1/7/2025 |
1.0.0-preview.4 | 28 | 1/7/2025 |
1.0.0-preview.3 | 28 | 1/7/2025 |
1.0.0-preview.2 | 25 | 1/7/2025 |
1.0.0-preview.1 | 29 | 1/7/2025 |