REST best practice
8 min
working with rest ids when a rest service returns an id, the jigx local data provider can automatically be synced with this id, eliminating the need to add a sync entities action to the jig 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 function jigx provider data provider rest method post # create new record in the backend url https //jigx training azurewebsites net/api/customers uselocalcall true parameters x functions key location header required false type string value #use manage jigx com to define credentials for your solution firstname type string location body required true lastname type string location body required true companyname type string location body required true address type string location body required false phone type string location body required false email type string location body required false inputtransform | { "firstname" firstname, "lastname" lastname, "companyname" companyname, "address" address, "phone" phone, "email" email } \# add the id to the output which ensures the local table, \# is automatically updated with the rest id once it is created outputtransform | { "id" custid, "status" status } 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 actions docid\ ygtqc7neyjmft y 9fyb4 , to sync the data with the onfocus or onrefresh events ensuring efficiency and reusability throughout the solution the global action is referenced in the solution's jigs to sync data from the rest server see rest syncing & loading local data docid\ ja i7rw5a3heeakscn4bv for an in depth 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 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 =@ctx current item addresses\[0] city leftelement element avatar text =@ctx current item addresses\[0] state "customers" \[ { "custid" 1, "firstname" "merilyn", "lastname" "bayless", "companyname" "20 20 printing inc", "addresses" \[ { "address" "195 13n n", "city" "santa clara", "county" null, "state" "ca", "zip" "95054" } ], "phones" \[ { "mobile" "408 758 5015", "office" "408 758 5015" } ], "email" "merilyn bayless\@cox net", "web" "http //www printinginc com", "region" "us west", "customertype" "silver", "jobtitle" "project manager", "logo" null },datasources customers type datasource sqlite options provider data provider local entities \ entity customers query | select cus id as id, json extract(cus data, '$ firstname') as firstname, json extract(cus data, '$ lastname') as lastname, json extract(cus data, '$ companyname') as companyname, json extract(cus data, '$ addresses') as addresses, json extract(cus data, '$ phones') as phones, json extract(cus data, '$ email') as email, json extract(cus data, '$ web') as web, json extract(cus data, '$ customertype') as customertype, json extract(cus data, '$ jobtitle') as jobtitle from \[customers] as cus order by json extract(cus data, '$ companyname') \# jsonproperties \ addresses \ phones data =@ctx datasources customers item type component list item options title =@ctx current item companyname subtitle =@ctx current item firstname & ' ' & @ctx current item lastname description =@ctx current item addresses\[0] city leftelement element avatar text =@ctx current item addresses\[0] state label title =$uppercase((@ctx current item customertype = 'silver' ? @ctx current item customertype @ctx current item customertype = 'gold' ? @ctx current item customertype '')) color \ when =@ctx current item customertype = 'gold' color color3 \ when =@ctx current item customertype = 'silver' color color14 onpress type action go to options linkto view customer parameters customer =@ctx current item 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 docid 9wb2qccnghytx65lhnuws 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 for more information see update multiple records in a single rest call https //docs jigx com/examples/update multiple records in a single rest call see also rest examples https //docs jigx com/examples/rest