paginated

This a simple one just confused, in making paginated APIs how do I know where to add the next property so the frontend developer knows it has a next page...how do I check where the next is going to be a + 1 or it's going to be null, in a database,
4 Replies
ErickO
ErickO2y ago
is it a big db? and is the limit per page dynamic or static? cause you can simply COUNT the elements divide by the limit of results per request and send back that number as the total number of pages there are
{
"items": [...],
"page": 1,
"total": 100,
"next": "https://api.example.com/items?page=2" // URL to next page of results
}
{
"items": [...],
"page": 1,
"total": 100,
"next": "https://api.example.com/items?page=2" // URL to next page of results
}
the response can look like that
Jochem
Jochem2y ago
If it's too large a dataset to COUNT, set your limit to per_page + 1, then pop the last result off
ErickO
ErickO2y ago
yeah that's why I asked the size of the db, COUNT can be slow if you have like...millions of rows but if you're not at that point COUNT + indexes is fine
Electronic
ElectronicOP2y ago
Sorry I never replied, was off
Want results from more Discord servers?
Add your server