An Application Programmable Interface or API allows two applications to interact with each other using the API as a bridge or intermediary. If you are not familiar with how to integrate an API then you may be spending a lot of time unnecessarily writing a lot of code from scratch. In other words, you may be working too hard! So what’s the catch? An IDE Software may help you to lessen the time spent on coding and integrating APIs into your applications.
Table of Contents
Are you wasting time by writing a lot of code from scratch?
This is the main reason you need to start considering integrating APIs into your software. So, we will talk about how to avoid reinventing the wheel every time you design an application. It’s not just the time expended coding things that could have been handled by the API; writing lots of additional code also means you open yourself up to the possibility that you inadvertently introduce errors – bugs – or unintended behavior. Your new code doesn’t benefit from the ‘wisdom of crowds’ which APIs can bring. A professional API from a specialist source often has many thousands of users/consumers who have used the API before and that means any problems and kinks have probably been caught and rectified before you even begin.
Letting someone else do the work is always the hard work is always the smart choice, isn’t it?
Is it hard to use an API?
When I got my first programming internship 4 years ago, in my first whole month, I spent my time integrating different APIs into the web app. I found integrating hard, but after integrating one API, it all become so easy and fun. All I had to do was pay attention to the documentation of the APIs. Using RAD Studio Delphi we also get some additional help to supercharge our skills. RAD Studio has tools such as the REST Debugger and the marvelously powerful REST components do all the hard work for us and help promulgate low code from us and maximum power from our apps.
By the end of this tutorial, you will learn how to employ these kinds of useful yet easy to use tools to easily and quickly integrate one of the market-leading APIs into your cross-platform Delphi application. This is the best-kept secret about Delphi that users of other computer languages often overlook – the “RAD” in RAD Studio stands for “rapid application development” and it’s not some kind of tricksy marketing trope; RAD Studio brings your apps from ideas into reality as fast as possible with that legendary rock-solid Delphi application stability means they keep on working too long after many competing technologies have fallen out of fashion or simply become obsolete due to their reliance on runtime support which atrophies over time.
What does this article teach me about using APIs in my desktop and mobile apps?
I hope that this tutorial will help you start your API Integrator career.
We will cover:
- Explore various APIs and see what they can do for our desktop and mobile applications
- Look and at how to integrate APIs for use in our own apps
- Code a demo cross-platform app using Delphi that integrates API
The only thing you need is a copy of RAD Studio and basic knowledge of the Delphi programming language!
Are you using automation to connect to an API?
We have dozens of tutorials on building a cross-platform app with Delphi FireMonkey and APILayer APIs. For instance, I have presented a cross-platform Delphi FireMonkey News application that utilizes MediaStack API.
How do I start using APIs, is there an example?
E-Commerce web applications utilize one API for instance Braintree for handling payments, and one API for handling the geolocation of the users to locate their address and show relevant products to them.
You can utilize the IPStack for IP intelligence and geolocation lookup. You can learn more about IPStack integration with Delphi FireMonkey powered demo application here: https://blogs.embarcadero.com/building-a-ip-to-geolocation-app/
How do APIs allow us to focus on core & unique features?
By choosing APIs, you can spend more time improving existing features and offering better core functionalities to your users. APILayer can be handy for automating many functions like:
- Language Detection
- VAT Number Validation
- Exchange Rates/Currency Conversion
- Phone Number or E-Mail Address Verification
How do APIs reduce the amount of maintenance we need to do with our apps?
If something goes off with the API, their dedicated teams immediately fix it. In the APILayer APIs, you can process millions of requests without a problem.
Overall, by incorporating APIs into your product, you can swiftly bring exceptional competitive software to the market. APIs can take care of your simple but critical functions in a quick way.
How can I integrate APIs Into my Delphi FireMonkey cross-platform Apps?
Delphi is the leading Rapid Application Development environment for more than 2 decades. You can quickly prototype any type of application and design it for multi-devices in no time. By choosing Delphi you can get 5X faster development time. That’s not an idle statement – Embarcadero have a whitepaper study to back up their claims.
In this brief tutorial, I’ll use Delphi FireMonkey and the built-in REST Client Library to integrate CountryLayer API.
What is the CountryLayer API?
CountryLayer API is the reliable real-time country data API for your business. You can retrieve accurate information about any country in the world.
You can enrich your product with accurate geodata.
You can get a free API access key by registering with the Free subscription plan
Before integrating any API, you need to learn how the API is designed and how the data is given to you. For that, you can utilize REST Debugger
With the REST Debugger, you can easily copy pre-configured REST Client components to the clipboard which you can the paste onto your app’s forms. Those components do all the hard work of sending and receiving requests to the API endpoint to get the data. We have utilized it in our app.
This is our Form Designer where we can design cross-platform native applications with Delphi FireMonkey.
How can I use LiveBindings with REST components in my low code Delphi apps?
Furthermore, with the power of LiveBindings Designer, we can connect our UI components with any data by linking them as you can see here.
If you need some customization every time you send requests to the API endpoint, we can write a little bit of code like this to get only one country-related information.
procedure TForm1.BtnSearchClick(Sender: TObject);
RESTClient2.Accept := 'application/json';
RESTClient2.AcceptCharset := 'UTF-8, *;q=0.8';
RESTClient2.BaseURL := Format('http://api.countrylayer.com/v2/name/%s?access_key=%s&fullText=%s', [Edit1.Text, 'a27f44dd66e6153fa97baf552a367554', 'True']);
var JSONValue := TJSONObject.ParseJSONValue(RESTResponse2.Content);
var JSONArray := JSONValue.GetValue<TJSONArray>('');
for var ArrayElement in JSONArray do
Memo1.Lines.Append('Name: ' + ArrayElement.GetValue<String>('name'));
Memo1.Lines.Append('Alpha2Code: ' + ArrayElement.GetValue<String>('alpha2Code'));
Memo1.Lines.Append('Capital: ' + ArrayElement.GetValue<String>('capital'));
Memo1.Lines.Append('Region: ' + ArrayElement.GetValue<String>('region'));
procedure TForm1.Button1Click(Sender: TObject);
This is our final result:
Why should I use an API in my apps?
So, to summarize:
- Using an API means avoiding writing lots of code – and lower code means fewer potential areas to make mistakes which means better quality.
- Somebody else does the hard work of integrating the often-complicated marshalling of data and statistics into easily consumable ‘bite-sized’ and well-organized chunks.
- The ‘wisdom of crowds’ means popular APIs have had many thousands, sometimes even millions, of users which means a much greater likelihood any errors or problems have already been found and resolved. Any new problems also get addressed much more quickly due to the API provider wanting to keep that same crowd happy before it turns into a rabble demanding satisfaction!
- An API means you are avoiding the cost and upkeep for infrastructure needed to gather information such as country data or IP intelligence. Some of that data may not even be readily available to individual developers or may require licenses and legal commitments which are beyond the reach of smaller organizations.
- Using an API, especially via RAD Studio Delphi’s overarchingly powerful REST debugger, the REST components and additional tools like LiveBindings makes it an almost trivial exercise for us to connect to an API – practically without any lines of code at all. Remember: Delphi and its component reuse design methodology has always strived to be the original low-code platform and remains so today.
Where can I find the source code for the demo of using the CountryLayer API in my Delphi app?
Here is the link for complete Delphi source code for the CountryLayer API demo: https://github.com/checkdigits/CountryLayer_example
APIs give you the ability to decrease engineering hours with optimal efficiency. Delphi gives you a 5X faster development environment and the ability to deploy your app to several platforms with a single code base. If you want to see for yourself why not download a free trial today?