Building Apps with Jigx
...
Data Providers
REST

REST best practice

8min

Working with REST IDs

  • When a REST service returns an id, the local data provider can automatically be synced with this id, eliminating the need to add a sync-entities action to the .
  • The id property must be added in the outputTransform of the REST data provider function.
  • This is useful on a POST (create) as a temp_id is created in the local data provider for the record when it is created. If the id is in the POST function outputTransform, the temp_id is automatically updated with the REST id once it is created on the REST side.
  • The below image shows how the local data provider creates a temp_id when a new customer is added. Then, it is automatically synced with the REST id because the id is in the function's outputTransform.

    Syncing temp_Id
    Syncing temp_Id
    
function.jigx


Where and when to sync and load data

Knowing when to load and sync data is important as it can impact the apps performance and functionality when the device is offline.

  • Load data in the Index.jigx file by adding an onFocus, and onLoad for performance. This also ensures that all data is available if the device goes offline.
  • Add the sync-entity or sync-entities action to a global action, to sync the data with the onFocus or onRefresh events ensuring effiecieny and reusablity throughout the solution. The global action is referenced in the solution's s to sync data from the REST server.
  • See REST syncing & loading local Data for an indepth explanation.

Working with complex REST structures

Working with complex REST objects can be tricky, as they include arrays, nested objects, and other complex data structures. When integrating and manipulating these JSON structures from the REST data provider configure the following:

  1. JsonProperties in the SQLite query jsonProperties: - addresses
  2. In the expression used to retrieve the value, specify the exact property in the array or nested object that you require by referencing the JsonProperty followed by the property. description: =@ctx.current.item.addresses[0].city leftElement: element: avatar text: =@ctx.current.item.addresses[0].state
Complex JSON
YAML


Data handling when a device is offline

  • Dealing with offline remote data is fundamental to ensuring data synchronization and consistency between the mobile app and the remote data source, allowing users to continue using the app and performing actions without interruption. Offline remote data handling explains how to configure solutions to deal with data when the device is offline.

Update multiple records in a single REST call

Updating multiple records in a single REST call helps optimize API usage by reducing the number of requests, which prevents hitting API rate limits and improves performance by minimizing client-server round-trip times. To implement this, use the execute-entities action to call the REST function. There are two configuration methods:

  • functionParameters: Use this for static values that are consistent across all records.
  • data property: Use this for dynamic values that vary per record.

See Also





Updated 21 Oct 2024
Doc contributor
Did this page help you?
Yes
No