Enable Pagination

You can configure an API flow to paginate response data from the REST Response object.

Pagination is a process that is used to divide large data into smaller discrete pages, thus allowing for less clutter and better readability. It also means that server request processing will be faster as a small subset is to be returned. Hence, improving the overall API performance and readability.

For our use case, we have an API flow that is configured to retrieve a collection of order items using a database lookup along with filter and sort functionalities enabled. Now, let us see how pagination can be configured in this flow.

01-Flow-API-Pagination

1. Right-click on the REST Response object and select Properties from the context menu.

02-Response-Properties

This will open the Properties window.

03-Properties-Window

2. Click Next until you reach the Response Configuration window.

This is where you can set up pagination options to better structure the response data fetched for a successful 200-OK request.

04-Response-Configuration

Enable Cursor Pagination: Checking this box lets the incoming data be paginated by a cursor. Cursor-based pagination works by returning a pointer to the last item in the dataset page, using which the client can make successive requests to read the next set of records iteratively. Once all records have been read, the cursor value becomes null, thus indicating that no more records are left to be read.

Page Size: This counter determines the number of records returned in a single requested page.

3. Click OK and the REST Response object will be configured in accordance with the cursor pagination and page size.

05-Cursor-Paginated

Note: Any request made to this endpoint will return the first n (page size) records along with a ‘cursor’ field in the response payload. This cursor field can then be reiterated in the next request as a Query Parameter named ‘Cursor’ to fetch the next n (page size) records.

At runtime, these paginated calls are cached at the server. To learn more about it, click here.