Connect to a REST Data Source
In the previous article, Edit Your Data, you edited data from a SQL data source. In this article, you connect to and display data from a remote REST-based data source.
In this article, you will:
- Deploy the custom REST plug-in
- Connect to a remote REST data source
- Create an entity from the REST data source
- Display the REST data in your app
Deploy the custom REST plug-in
You connect to data sources through AppStudio plug-ins. Appery supplies many types of plug-ins to support some of the most common data sources, such as Microsoft SQL Server , Oracle, and Salesforce. You can use some plug-ins right out of the box, and for others you can customize them.
In this example, you uses a custom REST plug-in to access a REST data source. This is the same plug-in that the eleVate sample app uses to access its data. If you have already installed and run the eleVate sample app, as describe in Restore and Deploy the Configuration Database, then you can skip this procedure.
To access the REST data source, you must download and install two files:
To install these files:
- Download the ElevateRESTPlugin.zip file.
- Extract both files to your local machine.
- Copy both files to the plugins folder of your AppServer. For example:
Connect to a remote REST data source
The REST plug-in uses an XML metadata file that describes the HTTP request and the desired REST service data. To access data using the REST plug-in, you create a data source in AppStudio that references the metadata file.
To connect to a REST data source:
- Start AppStudio and load the Hello World app.
- Select the Data Sources icon on the AppStudio toolbar. The Data Source Manager appears in the AppStudio Workspace.
- Click the Add button to add a new data source.
- Set the Name property to HelloWorldRemoteData.
Set the Plug-in Type to Elevate REST Plugin. This is the custom plug-in used to access the data used by the AppStudio elevate sample app.
If you do not see the Elevate Rest Plugin in the Plug-in Type dropdown, then you have to install it. See the Deploy the custom Rest plug-in procedure above for more information.
Click in the Lockout Minutes property to open the Connection Settings area of the Data Source Manager.
- In the General tab of the Connection Settings area, set the following property:
- Metadata file: http://demo.pyxismobile.com/rest/parseElevate.xml
The parseElevate.xml file file describes both the request from the plug-in to the REST service and the response from the REST service to the plug-in.
- Leave all other fields blank
- Click Test Connection. A confirmation dialog box appears if the connection was successful.
- Save the app.
The Data Source Manager appears as below:
Create an entity from the REST data source
Before you can access a data source, you first create an entity in AppStudio. An entity represent a table in a data source. After creating the entity in AppStudio, you can access the entity data fields, corresponding to the columns of the table, in your app.
To create an entity in AppStudio:
- In AppStudio, click the Data Entities icon in the toolbar. The Entity Navigator appears in the Workspace.
- Select the Data Sources icon in the lower-left corner of AppStudio.
- In Data Sources, click the plus icon next to HelloWorldRemoteData to expand it. You can now see the tables defined in the HelloWorldRemoteData data source.
- Click and drag the Contacts_Elevate table into the Entity Navigator. A new icon appears in the Entity Navigator named Contacts_Elevate.
- Save the app.
The Entity Navigator appears as below:
Display the REST data in your app
You can now use the the Contacts_Elevate entity to access the remote data using REST. To access the data, perform the steps in the Display Your Data article. Just replace the references to the contacts entity with the Contacts_Elevate entity.