DEV Community

Discussion on: Pagination in an API: page number vs start index

Collapse
 
joaofbantunes profile image
João Antunes

Agree, the cursor based pagination is certainly a great alternative, particularly in cases like the ones you mentioned.

Regarding the two "approaches" I mentioned in the post though, they are much more similar, the main difference is more of developer perception, not really having an impact on the end result as the choice between them and a cursor based approach have.

For an example of what I was thinking when I wrote this post:
Imagine an endpoint in which we want to get 10 items after skipping other 10, in the two examples:

  1. Page number and page size -> https://some-api/items?pageNumber=2&pageSize=10
  2. Start index and limit -> https://some-api/items?startIndex=10&limit=10

So my question was more regarding what people prefer between these two.

Collapse
 
mehdibenhemdene profile image
mehdibenhemdene

Well in this case I'd have to say that I really prefer the first method (page number and page size) because it's kind of similar to what the user is seeing and requesting (making it easier to render in client side instead of having to calculate the startIndex each time in case we want to display the page number in the UI for eg.).