RA.Utilities.Integrations 10.0.0

Prefix Reserved
dotnet add package RA.Utilities.Integrations --version 10.0.0
                    
NuGet\Install-Package RA.Utilities.Integrations -Version 10.0.0
                    
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="RA.Utilities.Integrations" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RA.Utilities.Integrations" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RA.Utilities.Integrations" />
                    
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 RA.Utilities.Integrations --version 10.0.0
                    
#r "nuget: RA.Utilities.Integrations, 10.0.0"
                    
#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 RA.Utilities.Integrations@10.0.0
                    
#: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=RA.Utilities.Integrations&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RA.Utilities.Integrations&version=10.0.0
                    
Install as a Cake Tool

RA.Utilities.Integrations

NuGet version Codecov NuGet Downloads Documentation GitHub license

RA.Utilities.Integrations is a utility library that simplifies and standardizes HTTP client calls in .NET applications. It solves the problem of managing external API integrations by providing a robust and repeatable pattern that centralizes configuration, simplifies registration, and improves resilience with built-in retry policies.

By building on IHttpClientFactory, it promotes best practices like using typed HttpClients, which provides better compile-time safety and intellisense.

Getting started

Install the package via the .NET CLI:

dotnet add package RA.Utilities.Integrations

Or through the NuGet Package Manager console:

Install-Package RA.Utilities.Integrations

๐Ÿ”— Dependencies

Additional documentation

For more information on how this package fits into the larger RA.Utilities ecosystem, please see the main repository documentation.


๐Ÿš€ Usage Guide

Hereโ€™s a step-by-step guide to setting up a typed client for an external API.

1. Add Configuration to appsettings.json

Define the settings for your integration. The section name (e.g., "MyApi") will be used later for binding.

{
  "Integrations": {
    "MyApi": {
      "BaseUrl": "https://api.example.com/v1/",
      "TimeoutSeconds": 60,
      "DefaultHeaders": {
        "X-Api-Key": "your-secret-api-key",
        "Accept": "application/json"
      }
    }
  }
}

2. Create a Settings Class

Create a class that inherits from HttpClientSettings to represent your configuration.

using RA.Utilities.Integrations.Options;

public class MyApiSettings : HttpClientSettings
{
    // You can add custom properties specific to this integration if needed.
}

3. Create a Typed HttpClient

This is the client your application will use to communicate with the API. It takes HttpClient in its constructor, which will be configured and provided by the IHttpClientFactory.

using System.Text.Json;

public interface IMyApiClient
{
    Task<Product?> GetProductAsync(int id);
}

public class MyApiClient : IMyApiClient
{
    private readonly HttpClient _httpClient;
    private readonly ILogger<MyApiClient> _logger;

    public MyApiClient(HttpClient httpClient, ILogger<MyApiClient> logger)
    {
        _httpClient = httpClient;
        _logger = logger;
    }

    public async Task<Product?> GetProductAsync(int id)
    {
        try
        {
            var response = await _httpClient.GetAsync($"products/{id}");
            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();
            return JsonSerializer.Deserialize<Product>(content);
        }
        catch (HttpRequestException ex)
        {
            _logger.LogError(ex, "Failed to retrieve product with ID {ProductId}.", id);
            return null;
        }
    }
}

// Example DTO
public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
}

4. Register the Client in Program.cs

Use the AddIntegrationHttpClient extension method to register your typed client and bind its settings.

using RA.Utilities.Integrations.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Register the typed client for "MyApi"
builder.Services.AddIntegrationHttpClient<IMyApiClient, MyApiClient, MyApiSettings>(
    builder.Configuration,
    configSection: "Integrations:MyApi"
);

// ... other services

var app = builder.Build();

5. Use the Client in Your Services

Inject your typed client interface (IMyApiClient) wherever you need to call the external API.

public class ProductService
{
    private readonly IMyApiClient _myApiClient;

    public ProductService(IMyApiClient myApiClient)
    {
        _myApiClient = myApiClient;
    }

    public async Task<Product?> GetProductDetails(int productId)
    {
        return await _myApiClient.GetProductAsync(productId);
    }
}
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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
10.0.0 193 11/23/2025
10.0.0-rc.2 101 10/31/2025