Do you want to add live exchange rates features to your applications? You can easily get live exchange rates in our C++ Builder and Delphi applications by using ExchangeRates API from the exchangeratesapi.io that is free for 250 requests monthly. It is very easy to set up and get data in JSON format, which means we can easily use the REST framework to connect this data.
If you’re wondering what a C++ Builder is, it is a C++ software that allows you to build Native Windows C++ apps and iOS apps 10x faster with less code. It also includes an HTTP and REST client library that invokes REST services, as well as AWS and Azure components that can be used to build exchange rate features into your applications.
Table of Contents
ExchangeRates API
Exchangerates API is delivering exchanging rates data live for more than 170 world currencies, with over 15 exchange rate data sources, It has several endpoints, where each of them serves a different purpose, use case. These endpoints have functionalities like receiving the latest exchange rates information for a specific set, or all currencies; conversion from one to another currency; receiving data Time-series for multiple or one currencies, and preserving the API daily for the fluctuation data.
Exchangerates API can be registered from exchangeratesapi.io and it has an API structure that has a unique identifier as an API key that gets passed into the API as an URL parameter access_key. This parameter serves as a unique identifying authentication with the Exchangerates API. So there is a limit (currently 250) to requests for free use. The API comes with several endpoints where each of them provides different functionality. If you purchase with a subscription plan, every paid subscription plan on Exchangerates.io is with 256-bit SSL encryption. Simply use the HTTPS protocol instead of HTTP in order to connect to the API through SS
The JSONP Callbacks is a feature included in the Exchangerates API. With this feature, we can specify the function name and send it into the API’s callback GET parameter and make the API respond to your request with the API response wrapped in that function.
REST
REST (Representational State Transfer) is a connectivity method that allows to get and post data to create interactive applications that use Web Services. REST uses a subset of HTTP. A Web service that uses this REST data transfer architecture is called a RESTful. This web service must provide its web resources in a text form and this service also allows contents to be read and modified with a stateless protocol and a predefined set of operations. REST is a new modern data transfer architecture that allows interoperability between the computer systems on the Internet that provide these services. REST is Backend as a Service (BaaS) can be used in REST Server or REST Client applications, it is an alternative to SOAP to access a Web service. client tutorial shows how to use the REST Client Library for accessing REST-based web services (REST stands for Representational State Transfer).
In C++ and Delphi , the REST library is available for all platforms that are supported by both of them. The REST Library framework focuses on JSON as the representation format. XML is not explicitly supported.
C++ Builder has many connectivity options like FireDAC SQL Connections to InterBase, IB Express, MSSQL, MySQL, PostgreSQL, SQLite, …; or TCP/IP Connections and many other connectivity options. C++ Builder has also REST-based connectivity as a Client or as a Server that provides you to do REST connections by the REST components that come with RAD Studio officially.
REST Debugger
We can easily set up the components by using REST Debugger Tool in RAD Studio (C++ Builder or Delphi). You can launch REST Debugger from the Tools menu of RAD StudioThe Embarcadero REST Debugger(The Latest version is 10.4.2) empowers developers to explore, test, and ultimately understand how a RESTful web service works. Dive right into REST data with filterable JSON blobs, streamlined OAuth 1.0/2.0 authentication, and configurable request/resource parameters. You can directly copy and paste REST components from the REST Debugger to the RAD Studio, Delphi, or C++Builder IDE. This enables the configuration and consumption of REST services in Delphi or C++Builder apps with just a few clicks.
REST Debugger allows you to test your connections easily, you can easily reach or transfer your data. There is also a free version that can be used by other REST tools and it can be downloaded from RESTdebugger.
In RAD Studio there is a good tool REST Debugger to test REST Requests (Gets, Posts, …) and it is very easy to automatically set up the REST components with their parameters.
Setting ExchangeRates API
Exchangerates API is very simple, here are the steps,
- Sign Up to Exchangerates API can registered from exchangeratesapi.io
- Get your API Access Key from the https://manage.exchangeratesapi.io/dashboard and simply attach your unique Access Key to one of the endpoints (here latest) as a query parameter: 1http://api.exchangeratesapi.io/v1/latest?access_key=062b3c167bdd65bf8f0e84169f85dabcIf you registered to Exchangerates API, your link example can be found in 3-Step QuickStart Guide. There are 5 main API Endpoints (latest, historical, convert, time series, fluctuation) through which you can access different kinds of data, all starting out with this Base URL.
- Integrate into your application
Now you can test your connection with REST Debugger or with your REST Client applications.
Connecting and Setting Components with the REST Debugger
To get exchange rate with REST Debugger, copy your URL with your API Key
For example we can easily read all exchange rates in Euro base by using this API link and Rest Debugger. Go to Tabular Data tab in REST Debugger and type ‘rates’ into JSON Root Elements and Apply. You will get all exchange rates as given example below;
One of the great feature of REST Debugger setups all components and features for your C++ Builder application. Just press to ‘Copy Components’, paste it to your form design.
REST Connection by using REST Debugger Settings
Easily a REST connection can be done by using REST components and REST Debugger in C++ Builder.
- Create a new Multi-Device C++ Builder application, save all unit and project files to a folder (i.e ExchangeRatesAPI )
- Set your ExchangeRates API Registration on their web page and use REST Debugger as described above.
If you copied components by using REST Debugger as given above, paste them to your form, and arrange their positions to see their names. - Add a Button (TButton) and a Memo (TMemo) component to see all JSON data.
- Double click to Button1, and modify as below,
1 2 3 4 5 6 7 8 9 |
void __fastcall TForm1::Button1Click(TObject *Sender) { RESTRequest1->Execute(); TJSONValue *jValue = RESTResponse1->JSONValue; Memo1->Lines->Add( jValue->ToString() ); } |
If you run your application you will see that it gets all data about all exchange rates in JSON format.
If you don’t want to use components copied by the REST Debugger, you can also manually follow the Tutorial using the REST Client Library from here
REST Connection with REST Components
Easily a REST connection can be done by using REST components in C++ Builder.
- Create a new Multi-Device C++ Builder application, save all unit and project files to a folder (i.e ExchangeRatesAPI )
- Add a Button (TButton) and a Memo (TMemo) component to see all JSON data.
- Drag RESTClient (TRESTClient , RESTRequest (TRESTRequest) and RESTResponse (TRESTResponse) and arrange their positions to see their names.
- Click to RESTClient1, and on the Object Inspector window,
Set your ExchangeRates API Registration on their web page as described above
As described in https://exchangeratesapi.io/documentation/ document
set its BaseURL property to “http://api.exchangeratesapi.io/v1” or you can modify at in code as below,
Double click to its Params and add two parameters; Endpoint with the Value=latest and access_key with the Value = YOUR API KEY parameters as below here,
5. Double click to Button1 and add RESTClient, RESTRequest parameters and retrieve results from RESTResponse as below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
void __fastcall TForm1::Button1Click(TObject *Sender) { //RESTClient1->BaseURL = "http://api.exchangeratesapi.io/v1"; //RESTClient1->AddParameter( "EndPoint", "latest", TRESTRequestParameterKind::pkGETorPOST); //RESTClient1->AddParameter( "access_key", "062b3c167bdd65bf8f0e84169f85d8abd", TRESTRequestParameterKind::pkGETorPOST); RESTRequest1->Resource = "latest"; RESTRequest1->Method = TRESTRequestMethod::rmGET; RESTRequest1->Response = RESTResponse1; RESTRequest1->Response->ContentType = "application/json"; RESTRequest1->Response->ContentEncoding="UTF-8"; RESTRequest1->Execute(); TJSONValue *jValue = RESTResponse1->JSONValue; Memo1->Lines->Add(jValue->ToString()); } |
Here the commented first 3 lines can be modified according your setup if you didn’t set it from the components properties as given steps above.
Sign up to Exchangerates API, it can registered from exchangeratesapi.io and try it in C++ Builder, it is also possible in Delphi too.
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. There is a free C++ Builder Community Edition for students, beginners and startups, it can be download from here and the professional developers can use the Professional, Architect or Enterprise versions of C++ Builder which has trial version and can be downloaded from here.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
According to their website, you only get 250 free requests per month, not 1000.
Yes, you are correct – that is the current value I see too. Sorry about that, it seems the value may have changed since the article was written (in April 2021) – I’ve updated the article to reflect the new 250 free figure.
Thank you Ian, I remember it was 1000 before, probably they reduced requests. Thank you Jannie!
The REST Debugger has its own Parameter tab, where things like the API key can be added. It’s the pendant to RESTClient1.AddParameter( “access_key” [..]
If you copy and paste the components from REST Debugger, it will then create these parameters within the design-time components, which is a great way to understand how these components work.