Created
February 1, 2019 13:32
-
-
Save DominikAngerer/811fe3ab01ec2f1ee95e6c0caa475131 to your computer and use it in GitHub Desktop.
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
// Option 1 | |
// if you know that you only want 2 | |
let per_page = 100 | |
let responses = await Promise.all([ | |
app.$storyapi.get('cdn/stories/', { | |
starts_with: 'posts/', | |
per_page: per_page, | |
page: 1 | |
}), | |
app.$storyapi.get('cdn/stories/', { | |
starts_with: 'posts/', | |
per_page: per_page, | |
page: 2 | |
}) | |
]) | |
// Option 2 | |
// according to specific story amount | |
let per_page = 100 | |
let requests = [] | |
let totalPages = 10 // 10 pages | |
for(let i = 0; i < totalPages; i++) { | |
requests.push(app.$storyapi.get('cdn/stories/', { | |
starts_with: 'posts/', | |
per_page: per_page, | |
page: ++i | |
})) | |
} | |
let responses = await Promise.all(requests) | |
// Option 3 | |
// all with preflight request | |
let per_page = 100 | |
let requests = [] | |
let initial = await app.$storyapi.head('cdn/stories/', { starts_with: 'posts/', per_page: 1, page: 1 }) | |
// access Total header -> Total amount of Stories | |
// and calculate Total amount of pages | |
let totalPages = Math.ceil(initial.headers.Total / per_page) | |
for(let i = 2; i < totalPages; i++) { | |
requests.push(app.$storyapi.get('cdn/stories/', { | |
starts_with: 'posts/', | |
per_page: per_page, | |
page: ++i | |
})) | |
} | |
let responses = await Promise.all(requests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment