![]() ![]() ![]() The third tab contains a TWebBrowser component for loading up the IMDB website to the page of the individual movie. The second tab contains the individual movie data from the second endpoint. The first tab contains the movie results from the movie search. The TabPosition property is set to none so the tabs themselves are hidden. Once this was complete I added a TTabControl to show the individual movie results from the second endpoint. At this point I had to start dynamically changing the REST API URL in order to add the page number to it. Next I added a Next and Previous button to move forward and backward in the REST API search results. You'll have to judge for yourself how successful it is. using the built in TFlowLayout or TGridPanelLayout. There are a number of different ways to handle displaying dynamic content like this and I was testing out a custom way like this vs. I built some other procedures to handle resizing and re-organizing the images within the TScrollBox depending on the size of the application and depending on if it is a mobile client or a desktop client. Now the movie records from the TFDMemTable show each of their movie poster images in the TScrollBox in the application. I parented the frame to a TScrollBox on the main form of the application and then executed a procedure which utilizes the TNETHTTPClient in the frame to download and load the movie poster image into the TImage component. For each result I created a new TFrame object which each contains a TImage and a TNetHTTPClient. I created a TFrame to handle the image downloads and I dynamically looped through the results in the TFDMemTable. The next thing I wanted to do was display the results of my REST API request and show the images for each of the movies listed in the TFDMemTable. At this point I have pretty much built a REST Client and I haven't even written any code yet. When this is complete I was able to set the Active property on the TFDMemTable to True and it automatically makes the REST call to the OMDb REST API endpoint and fills the TFDMemTable with the results. The only thing left to do now is to define the Field Definitions in the TFDMemTable.įor the OMDb API Search endpoint I wanted to define the following fields: Title, Year, imdbID, Type, Poster so I opened the FieldDefs property and added a new field setting the name to each of the names (like Title) and setting the DataType to ftString. It will paste in a TRESTClient, a TRESTRequest, a TRESTResponse, a TRESTResponseDataSetAdapter, and a TFDMemTable. Now you can go to your Form in the Delphi Form Designer and do Edit|Paste. The Copy Components button is where the magic happens. If you see that then you can click Copy Components and close the REST Debugger. Once you enter the JSON Root Element you should see the various result rows show up in the string grid. In the case of the OMDb API we want to set the JSON Root Element to "Search" to correctly process and import the JSON fields as tabular data. You can select the Tabular Data tab and then you will see the results of your REST API request. At the bottom of the REST Debugger client there are three tabs which are Headers, Body, and Tabular Data. Once you open the REST Debugger you can plug in the REST API URL and then press Send Request to hit the REST API and see the results. In Delphi you can access the REST Debugger by going to the Tools menu and selecting REST Debugger from the drop down. I used the REST Debugger that is built into Delphi to test out each endpoint and then to generate all of the components needed to access and consume the two OMDb REST endpoints. One end point is a search of the database and the second endpoint allows you to load data about a specific movie. For this app I discovered the Open Movie Database (OMDb) which has a REST API. Full source code is linked at the end of the article. I also wanted to built the app in a low code way so I utilized LiveBindings a bit to do this where it was appropriate. I wanted to build this app so that it was cross platform and would run on Android, iOS, macOS, and Windows with a single code base and single UI so I picked FireMonkey to do this. I wanted to build out a Christmas themed project in Delphi and what better way than to build a Christmas Movie finder app. It is quick and easy to build a REST client with Delphi.
0 Comments
Leave a Reply. |