9

I am seeing that more and more new APIs use page tokens to let the user move between the pages of results containing a lot of items. However from an API designer point of view I'm not clear on what the benefits of using a token are when compared to letting the user specify how many items he wants to skip.

So here are my questions :

  1. What are the benefits of using a page token over a start index ?
  2. Roughly, in high-level terms, how does the typical page token implementation keeps track of pages ? Caching all the results would be rather inefficient. I'm guessing that some sort of hash could be used, but I'm not sure what would be hashed to reconstruct the results.

Thank you

1 Answer 1

6
  1. What are the benefits of using a page token over a start index ?
  1. The page token is useful when you don't want users to move to the any given page without fetching first results. Since the next page token is only received when you access the previous page, users won't be able to cache a search and access content later. So the end users can't skip promoted (advertised) content.

  2. Can't do parallel requests

  1. Roughly, in high-level terms, how does the typical page token implementation keeps track of pages ? Caching all the results would be rather inefficient. I'm guessing that some sort of hash could be used, but I'm not sure what would be hashed to reconstruct the results.

This could vary, since the API is rest, the search criteria is already there, Simple way to do is to do the search again and get the page based on the hashing algorithm. Or it might even cache the search... but it is up to the implementation.

2
  • Great answer thanks, any pointer on what would be hashed in the hashing algorithm you mention ? (since the query is sent again, and in this case the results are not cached)
    – tobiak777
    Mar 22, 2016 at 9:51
  • 1
    It could be a hash of page number + some known constant, or it could be a key to a cached result page. Or it could be something entirely different... Mar 22, 2016 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.