By referring to the information provided in this documentation, you can utilize the key since
to enhance your queries.
When making a request, it is important to verify if the result list contains 100 items (which represents the per-request size, subject to change based on parameters).
If the list does contain 100 items, continue querying the API while passing the id of the last user in the result as the value for the since
parameter, enabling you to retrieve the next set of 100 users.
Option 1 (recommended): Employ pagination with octokit
as detailed in the documentation here
import { Octokit } from "octokit";
const octokit = new Octokit({ });
//! Take note of using paginate here
const data = await octokit.paginate("GET /users/{username}", {
per_page: 100,
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
});
console.log(data)
Option 2: Iteratively query until the result list no longer contains 100 users, indicating the end of the entire list.
A simplified example:
// MOCK ONLY
let users = [];
let last_user = 0;
while (True) {
let query = await fetch(`/users/{username}`, {
since: last_user
});
users.push(query.data.users);
if (query.data.users.length < 100 {
break;
}
last_user = query.data.users[query.data.users.length - 1]
}