https://github.com/stefh/freecurrencyapi
RestEase Client for Freecurrency API
https://github.com/stefh/freecurrencyapi
Last synced: 5 months ago
JSON representation
RestEase Client for Freecurrency API
- Host: GitHub
- URL: https://github.com/stefh/freecurrencyapi
- Owner: StefH
- License: mit
- Created: 2024-03-09T09:18:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-20T06:30:02.000Z (12 months ago)
- Last Synced: 2025-08-05T12:41:31.432Z (10 months ago)
- Language: C#
- Size: 42 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#  Freecurrency-API
Unofficial [RestEase](https://github.com/canton7/RestEase) C# Client for [freecurrencyapi](https://app.freecurrencyapi.com) which uses [IMemoryCache](https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory) to cache the results.
## NuGet
[](https://www.nuget.org/packages/Freecurrency-API)
## Configuration
You will need your ApiKey to use freecurrencyapi, you can get one [https://app.freecurrencyapi.com/register](https://app.fxapi.com/register).
Register the client via Dependency Injection:
``` csharp
services.AddFreecurrencyAPI(o =>
o.ApiKey = "[YOUR_API_KEY]"
);
```
## Usage
### Status
Returns your current quota
``` csharp
IFreecurrencyClient client = // get from DI
var statusResponse = await client.GetStatusAsync();
```
### Latest Exchange Rates
Returns the latest exchange rates. The default base currency is USD.
``` csharp
IFreecurrencyClient client = // get from DI
var rates = await _client.GetLatestExchangeRatesAsync(CurrencyCodes.USD, new [ CurrencyCodes.EUR, CurrencyCodes.AUD ]);
var rate = await _client.GetLatestExchangeRateAsync(CurrencyCodes.USD, CurrencyCodes.EUR);
```
### Historical Exchange Rates
Returns the latest exchange rates. The default base currency is USD.
``` csharp
// todo
```
### Currencies
Returns all supported currencies
``` csharp
IFreecurrencyClient client = // get from DI
var currencyResponse = await client.GetCurrency("EUR");
var currenciesResponse = await client.GetCurrencies(new [] { "EUR", "USD" });
var allCurrenciesResponse = await client.GetCurrencies();
```
### Options
``` csharp
public class FreecurrencyAPIOptions
{
///
/// The required BaseAddress.
///
[Required]
public Uri BaseAddress { get; set; } = new("https://api.freecurrencyapi.com/v1");
[Required]
public string ApiKey { get; set; } = null!;
///
/// Optional HttpClient name to use.
///
public string? HttpClientName { get; set; }
///
/// This timeout in seconds defines the timeout on the HttpClient which is used to call the BaseAddress.
/// Default value is 60 seconds.
///
[Range(1, int.MaxValue)]
public int TimeoutInSeconds { get; set; } = 60;
///
/// The maximum number of retries.
///
[Range(0, 99)]
public int MaxRetries { get; set; } = 3;
///
/// In addition to Network failures, TaskCanceledException, HTTP 5XX and HTTP 408. Also retry these s. [Optional]
///
public HttpStatusCode[]? HttpStatusCodesToRetry { get; set; }
///
/// The cache expiration time in minutes for the latest exchange rates.
/// Default value is 60 minutes.
///
[Range(0, int.MaxValue)]
public int GetLatestExchangeRatesCacheExpirationInMinutes { get; set; } = 60;
///
/// The cache expiration time in hours for the currencies.
/// Default value is 24 hours.
///
[Range(0, int.MaxValue)]
public int GetCurrenciesCacheExpirationInHours { get; set; } = 24;
}
```
## References
- https://freecurrencyapi.com/docs/
## Sponsors
[Entity Framework Extensions](https://entityframework-extensions.net/?utm_source=StefH) and [Dapper Plus](https://dapper-plus.net/?utm_source=StefH) are major sponsors and proud to contribute to the development of **Freecurrency-API**.
[](https://entityframework-extensions.net/bulk-insert?utm_source=StefH)
[](https://dapper-plus.net/bulk-insert?utm_source=StefH)