CurrencyLayer4NET 2.0.1

.NET Core 2.2 .NET Standard 2.0 .NET Framework 4.6.1
NuGet\Install-Package CurrencyLayer4NET -Version 2.0.1
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.
dotnet add package CurrencyLayer4NET --version 2.0.1
<PackageReference Include="CurrencyLayer4NET" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CurrencyLayer4NET --version 2.0.1
#r "nuget: CurrencyLayer4NET, 2.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install CurrencyLayer4NET as a Cake Addin
#addin nuget:?package=CurrencyLayer4NET&version=2.0.1

// Install CurrencyLayer4NET as a Cake Tool
#tool nuget:?package=CurrencyLayer4NET&version=2.0.1

CurrencyLayer4NET: A .NET library for CurrencyLayer API

NuGet Apache 2

CurrencyLayer4NET is a .NET library that makes it easier to do API calls to CurrencyLayer.com.

Using CurrencyLayer4NET

CurrencyLayer4NET provides 3 different levels of how you can make CurrencyLayer API calls: CLClient, CLManager, CLQueryBuilder.

CLClient

This is high-level class that operates its own entities like Currency, Quote, etc. For example, getting all currencies looks like that:

ICLClient clClient = new CLClient("YOUR_API_ACCESS_KEY");
IEnumerable<Currency> currencies = clClient.GetCurrencies();

Getting currencies exchange rates:

Currency eur = Currency.FromCode("EUR");
Currency cad = Currency.FromCode("CAD");

ICLClient clClient = new CLClient("YOUR_API_ACCESS_KEY");
IEnumerable<Quote> quotes = clClient.GetRates(new[] { eur, usd });
// or
IEnumerable<Quote> quotes = clClient.GetRates(new[] { "EUR", "USD" });

Pros:

  • You can operate simple objects

Cons:

  • Some methods are not implemented
  • Async methods not implemented

CLManager

This is low-level class that operates entities that are nearly exactly repeat CurrencyLayer API responses structure (CLCurrenciesResponse, CLQuotesResponse, etc). Getting all currencies looks like that:

ICLManager manager = new CLManager("YOUR_API_ACCESS_KEY");
CLCurrenciesResponse response = manager.GetCurrencies();

foreach (var currency in response.Currencies){
	Console.WriteLine($"Currency Code: {currency.Key}, Currency Name: {currency.Value}");
}

Pros:

  • Full support of CurrencyLayer API endpoints
  • Async methods are available

Cons:

  • Low-level response objects
  • JSONP Callback Function feature missing

CLQueryBuilder

This is low-level class that allows building and executing queries to CurrencyLayer API. This class operates the same response entities as CLManager does (CLCurrenciesResponse, CLQuotesResponse, etc). Getting all currencies looks like that:

CLCurrenciesResponse response = CLQueryBuilder.
                Create(Endpoints.CURRENCIES).
                GetResult<CLCurrenciesResponse>();

To request quotes for specified currencies, you can do this:

CLQuotesResponse response = CLQueryBuilder.
                Create(Endpoints.RATES).
                SetAccessKey("YOUR_API_ACCESS_KEY").
				SetCurrencies(new[] { "EUR", "GBP" }).
                GetResult<CLQuotesResponse>();

JSONP Callback function feature:

string response = CLQueryBuilder.
                Create(Endpoints.CURRENCIES).
                AddParameter("callback", "test_callback").
                GetResponse();

Pros:

  • Full support of CurrencyLayer API endpoints and features
  • Async methods are available

Cons:

  • Low-level response objects
  • In fact you build query manually, so you possibly will need to look at documentation to get the exact parameters for the query you want to make

Running Tests

In order to run Unit Tests you should perform the following simple steps:

  • If you do not have a CurrencyLayer account, sign up. If you already have the account, sign in.
  • You will need an API Access Key. You can find it on your Dashboard.
  • Open CurrencyLayerNET.Tests.TestConfiguration class.
  • Replace ApiAccessKey property value to your API Access Key.
  • Replace Plan enum property value to the corresponding Plan of your CurrencyLayer subscription plan. Example:
public static string ApiAccessKey { get; set; } = "b69242edc1d371e395060d3f414870d2";
public static Plan Plan { get; set; } = Plan.Professional;

Note: some of Unit Tests depend on your account subscription plan. So if you will set wrong Plan, some tests may fail.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
2.0.1 1,524 8/18/2019
1.0.0 2,098 2/19/2019

Added support for .NET Core 2.2 and .NET Standard 2.0