Afrowave.SharedTools.Api
0.0.2
See the version list below for details.
dotnet add package Afrowave.SharedTools.Api --version 0.0.2
NuGet\Install-Package Afrowave.SharedTools.Api -Version 0.0.2
<PackageReference Include="Afrowave.SharedTools.Api" Version="0.0.2" />
<PackageVersion Include="Afrowave.SharedTools.Api" Version="0.0.2" />
<PackageReference Include="Afrowave.SharedTools.Api" />
paket add Afrowave.SharedTools.Api --version 0.0.2
#r "nuget: Afrowave.SharedTools.Api, 0.0.2"
#:package Afrowave.SharedTools.Api@0.0.2
#addin nuget:?package=Afrowave.SharedTools.Api&version=0.0.2
#tool nuget:?package=Afrowave.SharedTools.Api&version=0.0.2
Afrowave.SharedTools.Api
This module provides universal HTTP and API communication utilities for Afrowave projects. It offers both static and dependency-injectable (DI) variants for handling web requests, data serialization, retries, and fault-tolerant communication. All components are fully compatible with .NET Standard 2.1 and can be used in desktop, web, and service environments.
📦 Contents
Models/HttpRequestOptions.cs– Configuration for timeout, proxy, and retry policyModels/RetryPolicyOptions.cs– Exponential retry with optional jitterInterfaces/IHttpService.cs– Unified API interface for async HTTP operationsDI/HttpService.cs– Injectable service implementing the interfaceStatic/HttpClientHelper.cs– Lightweight static helper (no DI required)Serialization/JsonOptions.cs– Preconfigured JSON serialization settings
⚙️ Purpose
Afrowave.SharedTools.Api acts as the networking foundation for all Afrowave tools. It standardizes request logic, response wrapping, retry behavior, and proxy handling — enabling consistent API access across backend, frontend, and CLI applications.
✅ IHttpService (DI)
A fully injectable HTTP service built around IHttpClientFactory.
Supports JSON, XML, text, and binary transfers with automatic retry logic.
public class MyClient
{
private readonly IHttpService _http;
public MyClient(IHttpService http)
{
_http = http;
}
public async Task<Response<MyData>> GetUserAsync()
{
return await _http.GetJsonAsync<MyData>("https://api.example.com/user");
}
}
Main methods:
GetJsonAsync<T>()PostJsonAsync<TReq, TRes>()GetStringAsync()GetBytesAsync()GetXmlAsync<T>()PostFormUrlEncodedAsync()GetJsonManyAsync<T>()(parallel requests)
Return type:
All methods return Response<T> from Afrowave.SharedTools.Models, providing consistent success, data, and error metadata.
⚙️ Static Helper
For projects without dependency injection (e.g. CLI tools, scripts, or test runners),
the static version HttpClientHelper offers identical features using a direct API.
var opts = new HttpRequestOptions
{
Timeout = TimeSpan.FromSeconds(10),
Retry = new RetryPolicyOptions { MaxRetries = 3 }
};
var res = await HttpClientHelper.GetJsonAsync<MyDto>("https://api.example.com", opts);
if (res.Success)
Console.WriteLine(res.Data.Name);
🧬 Configuration Models
HttpRequestOptions
Defines global behavior of HTTP clients. Members:
Uri BaseAddress– Base URL for requestsTimeSpan Timeout– Timeout durationbool UseProxy– Whether to use proxystring ProxyAddress– Proxy host and portbool AllowInvalidCertificates– Ignore SSL validation (for dev only)RetryPolicyOptions Retry– Retry configurationIDictionary<string,string> DefaultHeaders– Default headers (e.g., User-Agent)
RetryPolicyOptions
Controls exponential retry with optional random jitter. Members:
int MaxRetriesTimeSpan BaseDelaydouble BackoffFactorbool Jitter
🌐 Example Integration
Program.cs (DI registration)
services.AddHttpClient("AfrowaveHttpService");
services.AddSingleton(new HttpRequestOptions
{
Timeout = TimeSpan.FromSeconds(30),
DefaultHeaders = new Dictionary<string,string>
{
["User-Agent"] = "Afrowave-HttpService/1.0"
}
});
services.AddSingleton<IHttpService, HttpService>();
Usage in app code:
var res = await _http.PostJsonAsync<RequestDto, ResponseDto>(
"https://api.example.com/process", payload);
if (res.Success)
Console.WriteLine("Response OK");
🧱 Design Principles
- Compatible with .NET Standard 2.1
- No dependency on ASP.NET Core runtime — only
Microsoft.Extensions.Http - Optional proxy and SSL flexibility
- Consistent
Response<T>return type across all methods - Automatic retry and exponential backoff
- Parallel processing support for bulk HTTP operations
🧭 Structure
All classes include XML documentation and follow Afrowave naming conventions. Both static and DI versions share identical logic to simplify cross-project usage.
✍️ This file is part of the multilingual documentation system. Translations will be managed automatically by LangHub.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Afrowave.SharedTools.Models (>= 0.0.21)
- Microsoft.Extensions.Http (>= 10.0.0-rc.1.25451.107)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.