![smartmockupskrchx8jq | Embarcadero RAD Studio Delphi C++Builder Blogs smartmockups krchx8jq](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/smartmockups_krchx8jq-1246274.jpg?resize=1140%2C694&ssl=1)
Would you like to create an application with real-time flight status & global aviation data updated as often as every single minute? Whether it’s building booking platforms, visualizing and monitoring global flights, or creating popular flight tracking applications, wouldn’t it be nice to have a free, simple REST API for live flight tracking & airport timetable data? You’ve probably used one already, and, if you’re like me you’ve found a few of them a little lacking and thought “I could do that” – well, now you can!
![Captura de tela 20210720 155632 | Embarcadero RAD Studio Delphi C++Builder Blogs captura de tela 2021 07 20 15 56 32](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/Captura-de-tela-2021-07-20-15.56.32-7987732.png?resize=300%2C145&ssl=1)
Table of Contents
How to build a flight status app with as little code as possible
In this article, we will see how fast and easy it is to use windows app development tools like RAD Studio and Delphi to create a FireMonkey multi-device application using the LowCode Wizard in addition to a REST client library to take advantage of AviationStack API and retrieve a JSON format response for worldwide Live Flight tracker & airport timetable data.
What is the AviationStack API?
The AviationStack API offers instant access to live extensive set of aviation data, including real-time flight status, historical flights, schedules, airline routes, airports, aircrafts from 250+ countries and 13.000+ airlines from all around the world. This is possible to be done for free (up to first 500 calls/month; no credit card required) and much more is available at very affordable prices and scalable to the use you make with no upfront commitments.
Our RAD Studio and Delphi applications will be able to call the API and request information based on the name of parameters you provide.
How do I set up the AviationStack API?
Make sure you refer to AviationStack API website (https://aviationStack.com/) and and SignUp for the free Plan providing only your email and some basic information (no credit card required). Once you are in the website will redirect you to a Quickstart guide dashboard and your API Access Key will be provided. The Access Key unique, personal and is required to authenticate with the API. Keep it safe!
How do I call AviationStack API endpoints?
Now all we need to do is to call the API base URL (http://api.aviationStack.com/) via a HTTP POST method with no JSON request body needed and some few requested parameters added to the URL address depending on the ednpoint we choose to call. One can do that using REST Client libraries available on several programming languages.
AviationStack offers several API endpoints to choose from:
- Real-Time Flights: Look up flights in real-time
- Historical Flights: Look up historical flights
- Airline Routes: Look up airline routes
- Airports: Look up global airports
- Airlines: Look up global airlines
- Airplanes: Look up airplanes/aircrafts
- Aircraft Types: Look up aircraft types
- Aviation Taxes: Look up aviation taxes
- Cities: Look up global cities
- Countries: Look up countries
Our demo will focus on the Real-Time Flights Endpoint but all the others follow similar logic but with different parameters passed. For a complete and detailed list of endpoints and their parameters make sure you refer to AviationStack Quickstart guide (https://aviationStack.com/quickstart)
1 2 3 4 5 6 7 8 |
// Real-Time Flights (For the free subscription the request should be done using http and not https in the link below) https://api.aviationstack.com/v1/flights ? access_key = YOUR_ACCESS_KEY // optional parameters: & limit = 100 & offset = 0 // more parameters available please refer to the API Documentation (https://aviationstack.com/documentation) |
What does the AviationStack API endpoint return?
After the call the main results will be a very complete list with flights filtered based on the parameters you sent. The list below shows the first ten results I got when I called the API with parameters limit=10. For the free subscription the request should be done using http and not https otherwise you may get an error message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
{"pagination": {"limit":3, "offset":0, "count":3, "total":332928}, "data":[{ "flight_date":"2021-07-22", "flight_status":"scheduled", "departure":{"airport":"Noibai International", "timezone":"Asia/Ho_Chi_Minh", "iata":"HAN", "icao":"VVNB", "terminal":"T2", "gate":null, "delay":null, "scheduled":"2021-07-22T02:40:00+00:00", "estimated":"2021-07-22T02:40:00+00:00", "actual":null, "estimated_runway":null, "actual_runway":null}, "arrival":{"airport":"Guangzhou Baiyun International", "timezone":"Asia/Shanghai", "iata":"CAN", "icao":"ZGGG", "terminal":"1", "gate":null, "baggage":null, "delay":null, "scheduled":"2021-07-21T05:20:00+00:00", "estimated":"2021-07-21T05:20:00+00:00", "actual":null, "estimated_runway":null, "actual_runway":null}, "airline":{"name":"China Southern Airlines", "iata":"CZ","icao":"CSN"}, "flight":{"number":"8026", "iata":"CZ8026", "icao":"CSN8026", "codeshared":null}, "aircraft":null, "live":null}, {"flight_date":"2021-07-21","flight_status":"cancelled","departure":{"airport":"Naha","timezone":"Asia/Tokyo","iata":"OKA","icao":"ROAH","terminal":null,"gate":null,"delay":null,"scheduled":"2021-07-21T08:05:00+00:00","estimated":"2021-07-21T08:05:00+00:00","actual":null,"estimated_runway":null,"actual_runway":null},"arrival":{"airport":"Hirara","timezone":"Asia/Tokyo","iata":"MMY","icao":"ROMY","terminal":"D","gate":null,"baggage":null,"delay":null,"scheduled":"2021-07-21T09:00:00+00:00","estimated":"2021-07-21T09:00:00+00:00","actual":null,"estimated_runway":null,"actual_runway":null},"airline":{"name":"Japan Transocean Air","iata":"NU","icao":"JTA"},"flight":{"number":"801","iata":"NU801","icao":"JTA801","codeshared":null},"aircraft":null,"live":null},{"flight_date":"2021-07-21","flight_status":"cancelled","departure":{"airport":"Naha","timezone":"Asia/Tokyo","iata":"OKA","icao":"ROAH","terminal":"D","gate":null,"delay":null,"scheduled":"2021-07-21T08:05:00+00:00","estimated":"2021-07-21T08:05:00+00:00","actual":null,"estimated_runway":null,"actual_runway":null},"arrival":{"airport":"Kagoshima","timezone":"Asia/Tokyo","iata":"KOJ","icao":"RJFK","terminal":"D","gate":null,"baggage":null,"delay":null,"scheduled":"2021-07-21T09:25:00+00:00","estimated":"2021-07-21T09:25:00+00:00","actual":null,"estimated_runway":null,"actual_runway":null},"airline":{"name":"Solaseed Air","iata":"6J","icao":"SNJ"},"flight":{"number":"84","iata":"6J84","icao":"SNJ84","codeshared":null},"aircraft":null,"live":null}]} |
How do I connect my applications to AviationStack API?
Once you have followed basic steps to set up the AviationStack API we need to make sure we are able to connect and communicate with it before we start writing some code.
RAD Studio Delphi and C++Builder make it very easy to connect to APIs as you can you REST Debugger to automatically create the REST components and paste them into your app.
In Delphi all the job is done using 3 components tot make the API call. They are the TRESTClient, TRESTRequest, and TRESTResponse. Once you connect the REST Debugger successfully, copy and past the components you will notice that the API URL is set on the BaseURL of TRESTClient. On the TRESTRequest component you will see that the request type is set to rmPOST, the ContentType is set to ctAPPLICATION_JSON, and that it contains one request body for the POST.
How do I run the RAD Studio REST Debugger?
Run your RAD Studio Delphi and on the main menu click on Tools > REST Debbuger. Configure the REST Debugger as follows marking the content-type as application/json, and adding the POST url, the JSON request body and the API key you created. Once you click the Send Request button you should see the JSON response, just like we demonstrated below.
![Captura de tela 20210720 164205 | Embarcadero RAD Studio Delphi C++Builder Blogs captura de tela 2021 07 20 16 42 05](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/Captura-de-tela-2021-07-20-16.42.05-2315473.png?resize=750%2C587&ssl=1)
How do I build a FireMonkey Multidevice (Windows/MacOS desktop or Android/iOS mobile) application using the AviationStack API?
Low code app development is increasingly popular today, and for good reason: it speaks to the demand for software paired with the difficulty of creating it. In many ways, Delphi led the low code revolution: RAD, where you build software by connecting components in a visual designer, is low code. The key with many low code solutions is extensibility: low code which cannot be extended to a traditionally coded app has a hard upper limit of functionality. If you’re a technology adviser, you do not want to recommend something which will limit your client or company. The best development solutions that target low code provide an avenue to grow and extend. In this too, Delphi excels.
Until recently in Delphi you still had to create a new project and create the forms or screens yourself – no matter how little code you may have to write to get powerful functionality when you did. This is something we’ve now addressed with an addon to 10.4.2. Run your RAD Studio Delphi and on the main menu click on Tools > GetIt Package Manager. In GetIt for 10.4.2 and later search for “Low Code App Wizard for FireMonkey”, our technology for cross-platform applications.
![Captura de tela 20210714 1622112 | Embarcadero RAD Studio Delphi C++Builder Blogs captura de tela 2021 07 14 16 22 112 3](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/Captura-de-tela-2021-07-14-16.22.112-4932286.png?resize=750%2C422&ssl=1)
First steps in creating our cross-platform multidevice app
Now that you have installed Low Code App Wizard for FireMonkey and that you were able to successfully configure and test your API calls on the REST Debugger, go back to the REST Debugger and click the Copy Components button. Open RAD Studio Delphi and on the main menu click File > New> Multi-Device Application Delphi, select the Firemonkey Template App as shown below and follow some simples Wizard steps to create your Low Code application.
![Captura de tela 20210714 162350 | Embarcadero RAD Studio Delphi C++Builder Blogs captura de tela 2021 07 14 16 23 50 2](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/Captura-de-tela-2021-07-14-16.23.50-8833109.png?resize=750%2C422&ssl=1)
The result will be a fully functional cross-platform application, which already contains basic functionality that every mobile app will need — you can run and use the app as is — and hooks to build more, plus demonstrates application development best practices with a very clean extensible design to add more screens with low code, plus a set of tests to ensure your app remains high quality as you customise it.
What kind of things are in apps made by the LowCode App Wizard? Can I change any of them?
The app that Delphi builds for you is configurable through the wizard and you can choose any set of the following:
- User accounts: sign up, sign in, and a profile screen, with hooks for your own authentication
- Settings screen (where you can change the app theme (light or dark), plus some example settings you can reuse or extend)
- Contacts screen
- Terms of Use, About, and Privacy policy screens, easily configurable for your own data
- A database layer: using Interbase, store data in your app
- An example new screen you can use as a template or example for adding new functionality
As you can see the Wizard saves you a lot of time as it creates a complete project with many forms ready for you to implement the code. Open the recently created NewFormFrame and hit Ctrl+V in order to paste the components you copied from REST Debbuger. This acction will result in three components added to the the form RESTClient1, RESTRequest1 and RESTResponse1.
Adding some additional code to our LowCode App
Now we will simply add very simple code to a TButton OnClick event to make sure every thing is configured correctly and voila! In five minutes we have made our very first call to AviationStack API and we are able to receive JSON response for whatever parameter we want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
procedure TNewFormFrame.Button1Click(Sender: TObject); begin inherited; memo1.Lines.text := ''; RESTClient1.ResetToDefaults; RESTClient1.Accept := 'application/json, text/plain; q=0.9, text/html;q=0.8,'; RESTClient1.AcceptCharset := 'UTF-8, *;q=0.8'; RESTClient1.BaseURL := 'http://api.aviationstack.com/v1/'; RESTClient1.HandleRedirects := True; RESTClient1.RaiseExceptionOn500 := False; //here is were we pass the access_key and the additional parameters RESTRequest1.Resource := Format('?access_key=%s&limit=%s&offset=%s', [edit1.Text, edit2.Text, edit3.Text]); RESTRequest1.Client := RESTClient1; RESTRequest1.Response := RESTResponse1; RESTRequest1.SynchronizedEvents := False; RESTResponse1.ContentType := 'application/json'; RESTRequest1.Execute; memo1.Lines.text := RESTResponse1.Content; end; |
The sample application features a TEdit as a place to paste in the access key and additional TEdit for each parameter, a TMemo to display the JSON results of the REST API call. Now you have every thing you need in order to interate with the response data and make your application process the information and present it visually in the way it better suits your needs!
Here are the results of the REST API call shown on our Delphi FireMonkey form
![Captura de tela 20210720 165524 | Embarcadero RAD Studio Delphi C++Builder Blogs captura de tela 2021 07 20 16 55 24](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/Captura-de-tela-2021-07-20-16.55.24-6258066.png?resize=750%2C422&ssl=1)
In this blog post we’ve seen how to sign up for the AviationStack API in order to get instant access to structured and readable Real-time Flight Status & Global Aviation Data. We’ve seen how to use the RAD Studio REST Debugger to connect to the endpoint and copy that code into a real application. And finally we’ve seen how easy and fast it is to use RAD Studio Delphi and the Low Code App Wizard for FireMonkey to create a real Multidevice (Windows/MacOS desktop or Android/iOS mobile) application which connects to the API and retrives the data ready for you to iterate!
You can download the example source code from here: https://github.com/checkdigits/AviationApp_MediaStackAPI_example.
RAD Studio is an all-round development environment full to the brim with great features designed to get you developing powerful apps for Windows, macOS, iOS and Android rapidly and efficiently, Why not download a trial copy today?
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition