Data Providers
...
REST
Create an app using REST APIs

List & View customers (GET)

8min

Scenario

In this scenario, records are limited to return only fifty from the REST service. Continuation is used to ensure all customer records are returned. By pressing on the customer in the list of customers loads that specific customer's details in a form.

How does this work

The REST APIs GET operator is used in a function with an outputTransform to specify the exact data to be returned. A continuation is added to return all records; the records property specifies all records in the customer's table. A global action is configured to sync the data in the app with the REST data provider calling the function. In turn, the global action is called in the index.jigx file to load the data when the app is opened. In the list the local data provider is used to configure the list-item component. In the view-customer jsonProperties are used for address and phone to return the nested object.

List & view customer details
List & view customer details


This code sample builds upon the previous List customers (GET) step, to develop a complete and functional solution.

REST API

REST

Detail

URL

https://[your_rest_service]/api/customers

Operation/Method

GET

Function

Specify the REST API url and operation (method), parameters to include authentication in the header and in the outputTransform define the data properties to be returned. Add a continuation and record cofiguartion to return all records from the customers table.

rest-get-customer-cont.jigx


Action (global)

Create a load-data.jigx file under the actions folder. This file is configured with an action that syncs the data from the REST service, by calling the function, to the local Sqlite table. The action file is referenced in the index.jigx file to load the data when the app is opened or is in focus on the device.

load-data.jigx


Jig (screen)

  • Use a list type to configure a list of customers.
  • Since the data is already synced to the local Sqlite data provider, the s datasource is configured with a query to provide the data for use in the list.
  • Add an onPress to link to the view-customer .
  • In the datasource query of the view-customer use jsonProperties to return the complex structure for address and phone.
  • configure a queryParameter using inputs to return the customer details by id.
  • Expressions are used to reference the exact data property required in each component.
view-customer-details.jigx
list-customers.jigx


Index

For performance and offline support the data is synced from the REST service as soon as the app is opened or recieves focus. This is achieved by calling the global action in the OnFocus and onLoad events.

index.jigx