The Appmethod REST Library is a framework for accessing REST-based web services (REST stands for Representational State Transfer). The library is available for all platforms that are supported by Object Pascal.
The framework focuses on JSON as the representation format.
I thought I would create a tutorial that shows you how to access and retrieve data you have stored in a data collection on Parse.com. For Parse.com's REST API documentation, click here.
On Parse.com, I signed up for a new account and selected a name for my application. I then created a class called 'GameScore'. By default, Parse creates several fields for you, including createdAt, updatedAt and objectId. For my games sample application, I decided to add 2 more columns for my GameScore collection inside my Parse.com account. The first column was named 'PlayerName' with a String type and the second column was named 'Score' with a Number type. After creating the column, I added some sample data, i.e. PlayerName = Scott Mitchell and Score = 100;
Here is what I saw inside my Parse.com account:
Inside Appmethod, I went to File->New Mobile Application->Blank Application.
For the UI portion of my application, I dropped a TListView onto my form and set the alignment to alClient (you can access the ListView via the tool palette). I also placed a TToolbar onto my form with a parented TLabel (which displays the application title). TToolbar was aligned to the top, and the TLabel was aligned to alContents with the TextAlign property set to alCenter.
For TListView, I set the ItemAppearance to ListItemRightDetail. This exposes 2 bindable members (Text item and detail item) for me in the LiveBindings Designer. The LiveBindings Designer can be accessed via the View menu.
Next, we need to drop the REST components onto our form. For that, we need the following components:
For TRestClient, I set the Base URL to:
Next, we need to define our parameters:
Next, define your parameters as shown in the screenshot below. To add a new parameter, click on the yellow document icon. The IDs are found inside your Parse.com account under the 'App keys' tab:
You can leave the value for Score and PlayerName blank since we will retrieve that data from the server.
Now, let's right-click onto the FDMemTable component, select Fields Editor and then right-click inside the Fields Editor to add the data fields. On RESTResponseDataSetAdapter1, set the Dataset property to FDMemTable1.
Now, let's bind our Item.Text property to PlayerName and Item.Detail to Score:
You will also need to execute the Rest request at runtime:
procedure TForm2.FormCreate(Sender: TObject); begin RestRequest1.Execute; end;
This example requires an SSL encrypted connection to access the api. For Windows and iOS, this means you will need to install/include the SSL libraries. For Android, that is not necessary. More info on that topic can be found here.