Skip to content

Latest commit

 

History

History

ex-paginate

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

The Pagination Problem

See "How can I make a paginated API request?"

The Solution

This script is going to pull down all of the users from an API. It will use the stream-faqs server (see ../server.js) to respond to a total of two requests.

Request 1: "GET /users"

Response 1: Contains 50 users in a "users" array and a nextPageToken property.

Request 2: "GET /users?nextPageToken={{token returned in Response 1}}"

Response 2: Contains 50 users in a "users" array without a nextPageToken.

This mock API behaves as the Google APIs that I've been working with lately. See gcloud-streams-test for a complete example and analysis of memory usage.

Expectations

Both API requests will be made and the destination of our stream will receive an organized response containing a total of 100 users (50 users per call).

Try It

# Start the server (if it's not running already)
$ cd stream-faqs
$ npm install
$ npm start

# Run the example
$ cd ex-paginate
$ npm install
$ node .