Skip to content

TheLe0/frankfurter-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frankfurter .NET API Client

Tests CI

Introduction

The Frankfurter API is a powerful currency conversion API that allows you to retrieve up-to-date currency exchange rates for over 30 different currencies. With this .NET API client, you can easily integrate the Frankfurter API into your .NET applications and start converting currencies with just a few lines of code.

This API client is designed to make it simple and easy for developers to interact with the Frankfurter API. It provides a simple and intuitive interface that abstracts away the details of the underlying HTTP requests and responses, allowing you to focus on building great applications.

The client is built using the latest .NET technologies and follows modern best practices for software development. It is fully open source and actively maintained by a team of experienced developers, so you can be sure that it will be reliable, well-documented, and up-to-date with the latest features and bug fixes.

Whether you're building a financial application, a travel app, or any other type of application that needs currency conversion functionality, this .NET API client for the Frankfurter API is the perfect tool to get the job done quickly and easily.

Packages

Package Version Downloads Workflow
Frankfurter.API.Client NuGet Version NuGet Downloads Deploy
Frankfurter.API.Client.DependencyInjection NuGet Version NuGet Downloads Deploy

Domain

Here I am going to explain the entities containning on this API client. In this solution we not only wraps the API, but we shape the data in a way that is going to be easier to use:

  • Currency:Represents a currency, with its own enum code and name. Its a more informative thing;
  • CurrencyCode: Where we store all avaliable currencies codes, in that way developers can know what currencies are currently avaliable;
  • Exchange: Represents a exchange from a currency to multiple others;
  • CurrencyRate: Is just used inside the Exchange entity, where we represent the result of a conversion of a currency to another.

Avaliable Currencies

Currency Code Name
AUD Australian Dollar
BGN Bulgarian Lev
BRL Brazilian Real
CAD Canadian Dollar
CHF Swiss Franc
CNY Chinese Renminbi Yuan
CZK Czech Koruna
DKK Danish Kron
EUR Euro
GBP British Pound
HKD Hong Kong Dollar
HUF Hungarian Forint
IDR Indonesian Rupiah
ILS Israeli New Sheqel
INR Indian Rupee
ISK Icelandic Króna
JPY Japanese Ye
KRW South Korean Won
MXN Mexican Peso
MYR Malaysian Ringgit
NOK Norwegian Krone
NZD New Zealand Dollar
PHP Philippine Peso
PLN Polish Złoty
RON Romanian Leu
SEK Swedish Krona
SGD Singapore Dollar
THB Thai Baht
TRY Turkish Lira
USD United States Dollar
ZAR South African Rand

Note: We just wrap the API, so the currencies missing must be added on the Frankfurter API. We just consume its data.

Methods

  1. GetAllAvailableCurrenciesAsync: Returns all the currently avaliable currencies on the API
var currencies = await frankfurter
    .GetAllAvailableCurrenciesAsync()
    .ConfigureAwait(false);
  1. CurrencyConvertAsync: Do a currency convertion to a currency to another using a base amount.
var exchange = await frankfurter
    .CurrencyConvertAsync(
        10, // Reference Amount
        CurrencyCode.BRL, // Reference Currency
        CurrencyCode.USD // Currency to Convert
    ).ConfigureAwait(false);
  1. CurrencyConvertByDateAsync: Do a currency convertion to a currency to another using a base amount and a base date.
var exchange = await frankfurter
    .CurrencyConvertByDateAsync(
        DateTime.UtcNow, // Reference Date
        10, // Reference Amount
        CurrencyCode.BRL // Reference Currency
    ).ConfigureAwait(false);
  1. CurrencyConvertByLastPublishedDateAsync: Do a currency convertion to a currency to another using a base amount on the last published date;
var exchange = await frankfurter
    .CurrencyConvertByLastPublishedDateAsync(
        10, // Reference Amount
        CurrencyCode.BRL // Reference Currency
    ).ConfigureAwait(false);

this method returns the conversation for all avaliable currencies. You can pass an extra parameter and do the conversion only for the currencies that you want:

var toCurrencies = new List<CurrencyCode>
{
    CurrencyCode.EUR,
    CurrencyCode.USD
};

var exchange = await frankfurter
    .CurrencyConvertByLastPublishedDateAsync(
        10, // Reference Amount
        CurrencyCode.BRL, // Reference Currency
        toCurrencies // Currencies to convert
    ).ConfigureAwait(false);
  1. CurrencyConvertByDateIntervalAsync: Do a currency convertion to a currency to another using a base amount on a date interval;
var toCurrencies = new List<CurrencyCode>
{
    CurrencyCode.EUR,
    CurrencyCode.USD
};

var exchanges = await frankfurter
    .CurrencyConvertByDateIntervalAsync(
        10, // Reference Amount
        CurrencyCode.BRL, // Reference Currency
        toCurrencies, // Currencies to convert
        new DateTime(2020,1,1), // Start date
        new DateTime(2021,1,1) // End Date
    ).ConfigureAwait(false);

Configuration

This Api integration is ver simple, there is no authentication/authorization requirements, you can use it with almost no configurations.

You can instanciate this client in three different ways:

  1. Using default configs: This uses the default baseUrl, timeout and Throw on any error flag.
var frankfurter = new FrankfurterClient();

or by dependency injection:

services.AddFrankfurterApiClient();

2.Only configurating the API base url:

var frankfurter = new FrankfurterClient(baseUrl);

or by dependency injection:

services.AddFrankfurterApiClient(baseUrl);

3.And setup manually all configurations with your preferences:

var configuration = new FrankfurterClientConfiguration
{
  BaseApiUrl = baseUrl,
  MaxTimeout = 5000,
  ThrowOnAnyError = true
};

var frankfurter = new FrankfurterClient(configuration);

or by dependency injection:

var configuration = new FrankfurterClientConfiguration
{
  BaseApiUrl = baseUrl,
  MaxTimeout = 5000,
  ThrowOnAnyError = true
};

services.AddFrankfurterApiClient(configuration);

About

.NET client of the Frankfurter REST API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages