Practice.Backend.CurrencyConverter.Client 1.0.93

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

Practice.Backend.CurrencyConverter.Client

A typed, DI-friendly HTTP client library for the Currency Converter API. Publish as a NuGet package to share across services or environments.

Features

  • Typed ICurrencyConverterClient interface — easy to mock in tests
  • Configurable base URL — supports local, staging, and production environments
  • JWT bearer authentication via pluggable ITokenProvider
  • Built-in resilience: exponential retry + circuit breaker (via Microsoft.Extensions.Http.Resilience)
  • Options validation on startup — misconfiguration fails fast
  • Fully compatible with IHttpClientFactory and Microsoft's generic host

Installation

dotnet add package Practice.Backend.CurrencyConverter.Client

Quick Start

1. Configure via appsettings.json

{
  "CurrencyConverterClient": {
    "BaseUrl": "https://api.example.com",
    "ApiVersion": "1",
    "TimeoutSeconds": 30,
    "Retry": {
      "MaxAttempts": 3,
      "InitialDelaySeconds": 2
    },
    "CircuitBreaker": {
      "FailureRatio": 0.5,
      "BreakDurationSeconds": 60,
      "SamplingDurationSeconds": 60,
      "MinimumThroughput": 30
    }
  }
}

2. Register in DI

// From configuration section (recommended)
services.AddCurrencyConverterClient(
    builder.Configuration.GetSection(CurrencyConverterClientOptions.SectionName));

// Or inline
services.AddCurrencyConverterClient(options =>
{
    options.BaseUrl = "http://localhost:9081";
    options.TimeoutSeconds = 15;
});

3. Add Authentication (optional)

Option A — forward the incoming bearer token (ASP.NET Core apps):

services.AddDefaultHttpContextTokenProvider();

This forwards the Authorization: Bearer ... header from the current HTTP context — useful when the calling service already has a Keycloak token.

Option B — custom provider:

public class KeycloakTokenProvider(IKeycloakClient keycloak) : ITokenProvider
{
    public async Task<string?> GetTokenAsync(CancellationToken ct = default)
        => await keycloak.GetAccessTokenAsync(ct);
}

services.AddSingleton<ITokenProvider, KeycloakTokenProvider>();

If no ITokenProvider is registered, requests are sent without an Authorization header.

4. Inject and use

public class MyService(ICurrencyConverterClient client)
{
    public async Task<decimal> GetEurToUsdRateAsync(CancellationToken ct)
    {
        var response = await client.GetLatestExchangeRatesAsync(
            new LatestExchangeRatesRequest { BaseCurrency = "EUR" },
            ct);

        return response.Rates.GetValueOrDefault("USD");
    }

    public async Task<decimal> ConvertAsync(decimal amount, CancellationToken ct)
    {
        var response = await client.GetConversionAsync(
            new ConversionRequest { BaseCurrency = "EUR", ToCurrency = "USD", Amount = amount },
            ct);

        return response.Rates.GetValueOrDefault("USD");
    }
}

API

ICurrencyConverterClient

Method Returns Description
GetLatestExchangeRatesAsync(request, ct) ExchangeRateResponse Latest rates for a base currency
GetHistoricalExchangeRatesAsync(request, ct) HistoricalExchangeRateResponse Historical rates with optional date range and pagination
GetConversionAsync(request, ct) ExchangeRateResponse Convert an amount between two currencies

All methods throw CurrencyConverterApiException on API errors.

CurrencyConverterApiException

Property Description
StatusCode HTTP status code from the API
RequestUri The URI that produced the error
ResponseContent Raw response body (for diagnostics)
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
1.0.93 164 4/2/2026
1.0.91-dev 115 4/2/2026
1.0.89 147 4/1/2026
1.0.87-dev 117 4/1/2026
1.0.85 108 4/1/2026
1.0.83-dev 112 4/1/2026
1.0.81 123 3/31/2026
1.0.79-dev 115 3/31/2026
1.0.78 115 3/31/2026
1.0.75-dev 123 3/31/2026
1.0.72 116 3/31/2026
1.0.70-dev 109 3/31/2026
1.0.68 142 3/31/2026
1.0.66-dev 115 3/31/2026
1.0.64 119 3/31/2026
1.0.62-dev 113 3/31/2026
1.0.60 119 3/31/2026
1.0.58-dev 112 3/31/2026
1.0.55-dev 120 3/30/2026
1.0.52-dev 104 3/30/2026
Loading failed