Create pagination for infinite scrolling using REST API pagination
  • 23 Sep 2021
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

Create pagination for infinite scrolling using REST API pagination

  • Dark
    Light
  • PDF

Article summary

You can load large data sets on user search, for example, search by Category, on websites and apps by splitting data sets as different paginated endpoints. This is called infinite scrolling. 

Use the ModuleLimit and ModuleOffet parameters to paginate a module on a page. Use the Limit and Offset parameters for paginating the content for CategoryDetailModule.

Limit is already configured inside the filter of CategoryDetailModule. Now based on that limit, you can pass the next offset.  (If offset is not passed, then it will considered as 0 by default)

For example, the following API request will return the CategoryDetailModule which has ID 9968689a-7e9e-481c-975c-4f1d458c3e7a. If you see the filters section, it has limit and offset. Currently limit is configured as 10.

 The following is a code example to create video content pagination for infinite scrolling:

https://prod-api-cached-2.viewlift.com/content/pages?path=%2Fcategory%2Flive-ondemand&site=companyname&includeContent=true&moduleOffset=0&moduleLimit=3&languageCode=en&countryCode=GB

This means to get the next 10 content, you will pass offset as 10 in the API.

https://prod-api-cached-2.viewlift.com/content/pages?path=%2Fcategory%2Flive-ondemand&site=companyname&includeContent=true&moduleOffset=0&moduleLimit=3&languageCode=en&countryCode=GB&offset=10

Continue like this:

https://prod-api-cached-2.viewlift.com/content/pages?path=%2Fcategory%2Flive-ondemand&site=companyname&includeContent=true&moduleOffset=0&moduleLimit=3&languageCode=en&countryCode=GB&offset=20
https://prod-api-cached-2.viewlift.com/content/pages?path=%2Fcategory%2Flive-ondemand&site=companyname&includeContent=true&moduleOffset=0&moduleLimit=3&languageCode=en&countryCode=GB&offset=30
https://prod-api-cached-2.viewlift.com/content/pages?path=%2Fcategory%2Flive-ondemand&site=companyname&includeContent=true&moduleOffset=0&moduleLimit=3&languageCode=en&countryCode=GB&offset=40

There is also a flag hasNext inside the module which tells if more content is available for pagination. If its value is false, then you should stop at that point and should not do more pagination calls.



Was this article helpful?