Have you ever wanted your apps to have the power to examine an IP address and then find out everything you possibly could about it such as what time zone is local to the IP, what currency they use or what internet service provider is used? This capability is called IP address intelligence and it can add a powerfully rich package of knowledge to your applications allowing you to customize how you present information to your users. In this post you will be learn how to quickly and easily integrate IP address Intelligence into your Delphi desktop and mobile applications. We are going to use a service called IPApi, which is one of the market-leading solutions for all your IP Intelligence requirements in one place.
Why would we want to find out information about an IP Address?
The IP address is often tied to an individual user. If you know information about that IP address you can customize some of the information, services or even the user interface to better meet the needs of your users. For example, if you find out that the current time for the IP address is night time then you might want to offer different services to those you offer during their daytime hours. Knowing the local currency in use where the IP address is hosted allows you can offer that as a default for purchases.
Lastly, you may want or need to restrict some of app’s features if an IP address is located in a different country, possibly for security reasons or to comply with local laws or copyright compliance. With proper IP address intelligence information all of this should be possible.
What is the IPApi service?
The IPApi service is a powerful IP lookup RESTful web service that helps to find a different set of information using only the IP address. You can do more fascinating things with IP addresses. For instance:
- Content Personalization based on location
- Time Zone Lookup
- Language Redirection based on geolocation
- Currency and Fraud detection
- and more
The IPApi platform is platform agnostic and offers accurate information. IPApi say their RESTful web service is “trusted by 30,000+ businesses worldwide”.
How do I start getting information about an IP address in my application?
Head over to the IPApi official website to sign up. There is a Free plan to test it out.
How do I use IPApi to get information about an IP address?
After you sign up, you will have an API access key. And you can utilize that API access key to send requests to the endpoint.
Here is an example of calling to the endpoint:
And depending on your subscription plan, you get different sets of data in your response:
"continent_name": "North America",
"country_name": "United States",
"region_name": "New York",
"capital": "Washington D.C.",
"country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
"name": "US Dollar",
"plural": "US dollars",
"isp": "The City of New York"
Furthermore, you can have your IP lookup data in two different representations:
Here is a sample request for information about a particular IP address
While sending a request to the base API endpoint you need to specify output type XML or JSON. And here is a sample request for that:
Besides, you can customize response fields. Since the response size is big or you need only location data, for instance. So at this point, you can specify response fields also:
How do I connect my applications to the IPApi API so I can get information about IP addresses?
RAD Studio comes with its handy tools for different jobs. For instance, REST Debugger is one of the most popular tools when you work with RESTful web services. You can customize your API request methods, and based on the response from the endpoint, you can click the “Copy Components” button, which gives an already configured set of REST Client components. Then you can easily add them to your Delphi or C++ Builder project.
These REST Client components are TRESTClient, TRESTResponse, and TRESTRequest
How do I build an app which runs on Windows, macOS, Android & iOS and works with the IPApi API?
FireMonkey App Low Code Wizard is the new tool in the RAD Studio toolset, and we will use it in this tutorial.
FireMonkey Low Code Wizard makes the development process several times faster. You can create a fully functional Delphi cross-platform application in seconds. With the low code wizard, you will be asked what kind of features you want. For instance, Settings, Contacts, Profile, Home and Menu windows, and database layer for database needs and more. Moreover, you can customize your app as much as you can. You can read more about what the Low Code Wizard can do for you by clicking here: https://blogs.embarcadero.com/?s=low+code+wizard
How do you start Low Code App development in the RAD Studio Delphi IDE?
Download the newest community edition of Delphi IDE from here. And run the IDE, then go to the Tools menu and open GetIt Package Manager to download FireMonkey App Low-Code Wizard (https://getitnow.embarcadero.com/firemonkey-app-low-code-wizard/)
After installation is complete, you need to go on the menu: File->New->Other and select Multi-Device->Firemonkey Template App. And give the project name and choose the screens that you need.
The initial Low Code App Wizard screen
How can we connect RESTful web service and parse JSON in Delphi?
Well, we’ve already connected to the endpoint using the REST Debugger and copied REST components from it. Now we need to just design our blank new form, and here is our UI structure:
After you pasted the REST components that you copied from the REST Debugger, select the RESTRequest1 and open its Params property then clear the access key parameter. Because in this demo, we will customize and parse some exact values.
At this current state, you can call the endpoint using this one line of code:
Here is the final step to getting complete information about an IP address using Delphi
Create an OnClick event on the Check IP button and paste this code:
procedure TNewFormFrame.BtnCheckIPClick(Sender: TObject);
RESTClient1.Accept := 'application/json';
RESTClient1.AcceptCharset := 'UTF-8, *;q=0.8';
RESTClient1.BaseURL := Format('http://api.ipapi.com/api/%s', [EdtIP.Text]);
RESTResponse1.ContentType := 'application/json';
RESTRequest1.Resource := Format('?access_key=%s', [EdtAccKey.Text]);
var JSONValue := TJSONObject.ParseJSONValue(RESTResponse1.Content);
if JSONValue is TJSONObject then
LblLatitude.Text := 'Lat: ' + JSONValue.GetValue<String>('latitude');
LblLongitude.Text := 'Lon: ' + JSONValue.GetValue<String>('longitude');
LblIPLocation.Text := 'Location: ' + JSONValue.GetValue<String>('country_name');
LblCity.Text := 'City: ' + JSONValue.GetValue<String>('city');
LblZipCode.Text := 'Zip Code: ' + JSONValue.GetValue<String>('zip');
This is the finished Delphi IP address information mobile app example running
As you can see, creating a cross-platform application and integrating with RESTful web services is easy with Delphi FireMonkey!
Head over and download the full source code for the IPApi with Delphi demo here: https://github.com/checkdigits/IP-Intelligence-in-Delphi-using-ipapi_example
RAD Studio Delphi can easily make your great ideas become real applications in a very short space of time. Why not download a trial today and see for yourself?