How to implement the pagination?
Before we can proceed any further one should clearly examine the API provider’s documentation to get familiarised with the accepted method of pagination usage.
Description
Before we can proceed any further one should clearly examine the API provider’s documentation to get familiarized with the accepted method of pagination usage.
In order to avoid producing too many data, a component developer should use paging which is done in a combination with the snapshot feature.
Implementing paging with the help of snapshot
First, we would need to setup the snapshot object which would only have 2 properties: nextPage
and timestamp
. The property timestamp
is used to record the most recent update time of an object in the target system and the property nextPage
is used to remember the index of the next page to retrieve. Here is the algorithm behind:
-
At the beginning snapshot is empty, so that trigger queries based on timestamp
>= 1970
. -
If the API supports paging, trigger checks if the result is paged. If yes then the next page to retrieve is calculated and saved into the
nextPage
property in the snapshot. -
On next iteration, trigger checks if
nextPage
is available in the snapshot. If so it queries now the next page and overwrites thenextPage
with a new value. At the same time, it should preserve thetimestamp
timestamp for the later comparison. -
After iterating through all the pages, the
nextPage
parameter is removed from the snapshot. However, the timestamp property must stay in the snapshot. -
It is important to define max
timestamp
through all the pages. This is accomplished either by filtering or by comparing all thetimestamp
values in all pages with thetimestamp
in the snapshot.