Skip to content

Instantly share code, notes, and snippets.

@stonedem0
Created October 14, 2019 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stonedem0/29d6ff4d96c9f814fe3f97438cfa0c1b to your computer and use it in GitHub Desktop.
Save stonedem0/29d6ff4d96c9f814fe3f97438cfa0c1b to your computer and use it in GitHub Desktop.
meh
const needle = require('needle');
JSONStream = require('JSONStream'),
limit = 2000,
perPage = 10,
parser = JSONStream.parse()
let size = 0;
module.exports = function pagination(token) {
const options = {
headers: {
'Authorization': token
}
}
const stream = needle.get(`https://corporatevisions.sandbox.myabsorb.com/api/Rest/v1/Categories`, options)
.on('headers', header => {
console.log('header', header['content-length'])
size = header['content-length']
})
.pipe(JSONStream.stringify(false))
stream.pipe(parser);
parser.on('data', data => {
if (size > limit) {
let paginated = data.slice(0, perPage)
console.log('paginated data', paginated)
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment