Afrowave.SharedTools.Api 0.0.2

There is a newer version of this package available.
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
                    
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="Afrowave.SharedTools.Api" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Afrowave.SharedTools.Api" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Afrowave.SharedTools.Api" />
                    
Project file
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 Afrowave.SharedTools.Api --version 0.0.2
                    
#r "nuget: Afrowave.SharedTools.Api, 0.0.2"
                    
#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 Afrowave.SharedTools.Api@0.0.2
                    
#: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=Afrowave.SharedTools.Api&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Afrowave.SharedTools.Api&version=0.0.2
                    
Install as a Cake Tool

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 policy
  • Models/RetryPolicyOptions.cs – Exponential retry with optional jitter
  • Interfaces/IHttpService.cs – Unified API interface for async HTTP operations
  • DI/HttpService.cs – Injectable service implementing the interface
  • Static/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 requests
  • TimeSpan Timeout – Timeout duration
  • bool UseProxy – Whether to use proxy
  • string ProxyAddress – Proxy host and port
  • bool AllowInvalidCertificates – Ignore SSL validation (for dev only)
  • RetryPolicyOptions Retry – Retry configuration
  • IDictionary<string,string> DefaultHeaders – Default headers (e.g., User-Agent)

RetryPolicyOptions

Controls exponential retry with optional random jitter. Members:

  • int MaxRetries
  • TimeSpan BaseDelay
  • double BackoffFactor
  • bool 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.3 129 10/8/2025
0.0.2 132 10/6/2025
0.0.1 121 10/6/2025