• Blog
  • How a REST API call works in Delphi

How a REST API call works in Delphi

How to use the REST Debugger utility

Publish date:
Discover more of what matters to you

Overview

One of the most effective ways to create integrations for our software is to use the API (Application Programming Interface) structure.

APIs facilitate communication between a user and an application. But at the same time, users don’t need to know the details of the development process and the structure of the system that they will use.

What is REST? REST provides some specific criteria that are aimed at standardization and ensuring more flexible communication and access between different platforms and web services. 

When an API meets the standards suggested by the REST architectural style, it can be described as a RESTful API. 

In Delphi, REST API has some peculiarities in its functioning. Let’s have a look at them. To do it, we can build an example for Delphi rest-server consumption.

Let’s have a look at how a REST API call works in Delphi
Watch our step-by-step video guide
Watch

Delphi: rest server example of consumption

We will use a free apilayer that is available at: https://github.com/apilayer/restcountries.  

To open the REST Debugger, we should go to Tools -> Rest Debugger.

We have to choose which method we are going to use, and pass the URL with its parameters. 

In the case of this API, this is the URL: https://restcountries.com/v3.1

To filter all content, we need to use this URL: https://restcountries.com/v3.1/all

To filter a specific word, we should use this URL: https://restcountries.com/v3.1/name/word

*Word is the word to be filtered. 

In this case, we will use the “united” parameter to filter all parts that contain that word.

After entering the information, we have to click on Send Request.

Rest Debugger Menu

After sending the request and receiving the data in the REST Debugger, we can use the Copy Components button to make a snapshot of the configuration for the REST Client Library component which is required for building an application.

The next step is to insert it into your Delphi application. You can use your API either in VCL or FMX (Desktop or Mobile). In this REST API Delphi example, we will insert an edit button, DBGrid, and the data source to connect our grid. Let’s wire them up and execute the RESTRequest at design time to get a preview of the data:

Components of Rest Debugger

The code for filtering is very simple:

12345678
Procedure TFormExampleRest.btnSearchClick(Sender: TObject);
begin
if editSearch.Text = '' then
RestRequest1.Resource := 'all'
else
RestRequest1.Resource := 'Name/' + editSearch.Text;
RestRequest1.Execute;
end;

Reverse GeoCoding with the Position Stack API

In our second Delphi REST example, we will use the free version of a paid API, which can be found at: https://positionstack.com/

This API works the following way: it offers the service of geocoding, cartography, and many other possibilities. In our Delphi API REST example, we will use direct geocoding. We will send the address to receive latitude, longitude, and the information we get via the REST Debugger. To get the response, we should configure the JSON root using the data element:

Rest Debugger Menu

We have to send two parameters to receive the request. One of them is a developer key, which can be obtained from the website: https://positionstack.com (You can select a free version). The second parameter is the address from which we want to get the information.

Just as we have done in the first case, we will copy the components and insert them into the Delphi application. In this situation, the application can display the data at runtime. In our example, we will get the latitude and longitude of the city that we have indicated:

Result of Rest Request

Conclusion

With the use of a REST API, Delphi developers who build mobile or desktop applications can leverage a row of benefits. In Delphi, REST API is helpful for performing integrations and speeding up the building and implementation of innovative solutions.

At Softacom, we are proud to have seasoned Delphi experts. If you need technical assistance in Delphi software migration or development, we will always be ready to help you.

See how we modernize Delphi applications
Step-by-step migrations and expert consulting.
Explore
serge pilko softacom

Serge Pilko

Softacom Co-Founder Embarcadero MVP LinkedIn

We are actively using this technology because it combines ease of implementation with high performance to provide reliable and scalable integrations.

Subscribe to our newsletter and get amazing content right in your inbox.

This field is required
This field is required Invalid email address
By submitting data, I agree to the Privacy Policy

Thank you for subscribing!
See you soon... in your inbox!

confirm your subscription, make sure to check your promotions/spam folder

Get in touch
Our benefits
  • 17+ years of expertise in legacy software modernization
  • AI Migration Tool:
    faster timelines, lower costs, better accuracy (99.9%)
  • Accelerate release cycles by 30–50% compared to manual migration
  • 1–2 business day turnaround for detailed estimates
  • Trusted by clients across the USA, UK, Germany, and other European countries
Review
Thanks to Softacom's efforts, the solutions they delivered are already in use and have increased revenue streams.
  • Niels Thomassen
  • Microcom A/S
This field is required
This field is required Invalid email address Invalid business email address
This field is required
By submitting data, I agree to the Privacy Policy
We’ll reply within 24 hours — no sales talk, no spam