Created
October 14, 2019 16:28
-
-
Save stonedem0/29d6ff4d96c9f814fe3f97438cfa0c1b to your computer and use it in GitHub Desktop.
meh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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