Building Apps with Jigx
...
Data Providers
REST
REST best practice
6min
- 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 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.
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.
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:
- JsonProperties in the SQLite query jsonProperties: - addresses
- 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: [email protected][0].city leftElement: element: avatar text: [email protected][0].state
- 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.
Updated 20 Aug 2024
Did this page help you?