Paginate web services - Fluid Topics - Latest

Fluid Topics API Reference Guide

Category
Reference Guides
Audience
public
Version
Latest

It is possible to paginate certain Fluid Topics web services by defining optional query parameters as follows:

${webservice_path}?page=$PAGE_NUMBER&per_page=$NUMBER_OF_RESULTS_PER_PAGE

Where:

  • page: the page number, starting at 1.
  • per_page: the number of items per page.

It is also possible to paginate Fluid Topics web services by defining optional fields in the request body. In this case, the correct format of the fields is page and perPage (as opposed to page and per_page when defined as parameters in the query string).

Once the web service returns an empty result list, it means that is has crawled the entire content.

  • If paging parameters are present as both query parameters and fields in the request body, the query parameters take precedence.
  • It is strongly recommended to use pagination because performance suffers when calling a web service without pagination for portals with a significant amount of data.

If the page and per_page query parameters are not set manually, the page=1&per_page=-1 values are set automatically by default. All results are on a single page.

If the list ends on the last page, it may contain fewer results than the number in the query parameter.

Example of adding pagination parameters to the query string

The following example shows how to retrieve the first page of results and display 20 results per page:

/api/khub/documents?page=1&per_page=20

Response body

Without pagination, the following web service:

/api/khub/documents

returns the following result:

[
  {
    "id": "lahoGtFmU1Oh4LEKZ5PRA",
    "filename": "1.png",
    "title": "1",
    "mimeType": "image/png",
    "documentApiEndpoint": "/api/khub/documents/lahoGtFmU1Oh4LEKZ5PRA",
    "metadata": [ ]
  },
  {
    "id": "mahkBtZmU4Ot4QSAZ5BRE",
    "filename": "2.mp4",
    "title": "2",
    "mimeType": "video/mp4",
    "documentApiEndpoint": "/api/khub/documents/lahoGtFmU1Oh4LEKZ5PRA",
    "metadata": [ ]
  },
    ...
  {
    "id": "VHxDrn6h7bmvvXDpFqSrhw",
    "filename": "20.jpg",
    "title": "20",
    "mimeType": "image/jpeg",
    "documentApiEndpoint": "/api/khub/documents/VHxDrn6h7bmvvXDpFqSrhw",
    "metadata": [ ]
  },
  {
    "id": "Ve0yD1R8wcjT0x66pDZwgA",
    "filename": "21.TIF",
    "title": "21",
    "mimeType": "image/tiff",
    "documentApiEndpoint": "/api/khub/documents/Ve0yD1R8wcjT0x66pDZwgA",
    "metadata": [ ]
  }
]

With pagination, it is possible to use the same web service to return 20 results per page.

The following web service retrieves results for the first page:

/api/khub/documents?page=1&per_page=20

With the following response:

[
  {
    "id": "lahoGt~FmU1Oh4LEKZ5PRA",
    "filename": "1.png",
    "title": "1",
    "mimeType": "image/png",
    "documentApiEndpoint": "/api/khub/documents/lahoGt~FmU1Oh4LEKZ5PRA",
    "metadata": []
  },
  {
    "id": "mahkBt~ZmU4Ot4QSAZ5BRE",
    "filename": "2.mp4",
    "title": "2",
    "mimeType": "video/mp4",
    "documentApiEndpoint": "/api/khub/documents/lahoGt~FmU1Oh4LEKZ5PRA",
    "metadata": []
  },
  ...
  {
    "id": "VHxDrn6h7bmvvXDpFqSrhw",
    "filename": "20.jpg",
    "title": "20",
    "mimeType": "image/jpeg",
    "documentApiEndpoint": "/api/khub/documents/VHxDrn6h7bmvvXDpFqSrhw",
    "metadata": []
  }
]

The following web service retrieves results for the second page:

/api/khub/documents?page=2&per_page=20

With the following response:

[
  {
    "id": "Ve0yD1R8wcjT0x66pDZwgA",
    "filename": "21.TIF",
    "title": "21",
    "mimeType": "image/tiff",
    "documentApiEndpoint": "/api/khub/documents/Ve0yD1R8wcjT0x66pDZwgA",
    "metadata": [ ]
  }
]

As there are only 21 items on the portal, the web service returns only 1 item on the second page.

The following web service attempts to retrieve results for the third page:

api/khub/documents?page=3&per_page=20

Since there is nothing more to return, an empty response confirms that the web service has crawled the entire content:

[ ]