![]() |
Using Apilayer REST APIs from Delphi
As you might have seen online, Idera (Embarcadero parent company)*recently
![]() ![]() http://blog.marcocantu.com/images/fo...apilayer00.png In this blog post, I don't want to discuss the available services, but focus on how to call them from RAD Studio. I'll use only two services, the free and open REST countries API and one of their premium geolocation services. Using the REST Countries API My starting point for exploring apilayer*services is a simple and totally free service, available along with full documentation at* ![]() http://blog.marcocantu.com/images/fo...apilayer01.png Once the data looks correct in the REST Debugger, you can just use the Copy Components button to make a snapshot of the configuration for the REST Client Library component required for building an application. Now, create a Delphi or C++ application in RAD Studio, either VCL or FMX, and paste the components in a data module -- or a form if you are lazy. In this case I've used Delphi and VCL... and I was lazy. I dropped a panel with an edit and a button and DBGrid (plus a DataSource component), wired them up, and executed the RESTRequest at design time to get a preview of the data: http://blog.marcocantu.com/images/fo...apilayer02.png The code for filtering is very simple: procedure TForm43.Button1Click(Sender: TObject); </br> begin </br> * if Edit1.Text = '' then </br> * * RESTRequest1.Resource := 'name' </br> * else </br> * * RESTRequest1.Resource := 'name/' + Edit1.Text; </br> * RESTRequest1.Execute; </br> end; The only other change I ahd to do was to change the TypesMode property of the RESTResponseDataSetAdapter1 component to*JSONOnly, as some of the data analysis was mistakenly trying to convert some timezone related text to a date, resulting in an exception. Reverse GeoCoding with the Position Stack API Next I made an attempt at using the free level of a paid API,* ![]() http://blog.marcocantu.com/images/fo...apilayer03.png In this case, you need to sign up for a developer key and enter it as an additional parameter for the request. (You might want to consider encoding that key rather than having it as a plain string in the final application.) Now, similarly to what I've done above, we can copy the components into a RAD Studio application and have a geo coding FMX app good to go, this time based on Live Bindings. Also this app can display data at design time, in this case the latitude and longitude of my city (plus another city with the same name in the USA): http://blog.marcocantu.com/images/fo...apilayer04.png Conclusion Leveraging micro-service APIs for application development, both desktop and mobile, can really speed up building and deploying innovative features, and have them on a scalable infrastructure at the same time. I'm looking forward to leverage more of the ![]() http://feeds.feedburner.com/~r/marco...~4/RrzSH1V1GgQ ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:26 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz