API pagination best practices

I’d love some some help handling a strange edge case with a paginated API I’m building.

Like many APIs, this one paginates large results. If you query /foos, you’ll get 100 results (i.e. foo #1-100), and a link to /foos?page=2 which should return foo #101-200.

Unfortunately, if foo #10 is deleted from the data set before the API consumer makes the next query, /foos?page=2 will offset by 100 and return foos #102-201.

This is a problem for API consumers who are trying to pull all foos – they will not receive foo #101.

What’s the best practice to handle this? We’d like to make it as lightweight as possible (i.e. avoiding handling sessions for API requests). Examples from other APIs would be greatly appreciated!

12 Answers
12

Leave a Comment