I'm trying to implement pagination in a concise way and I seem to have a problem that I'm going to describe below.
The client wants the server to return a total number of pages. First I have to do some calculations on the server (apply various filters and that sort of things) and then shape a list of items to return. Then I have to paginate the list according to the items_per_page
parameter that I receive from the client in a query string, I also have a default value in case I don't get it from the client.
However the client wants to have a total number of pages, so that it could render a list of page links that looks like this << 1 2 3...103 >>
. It does not seem right to me to return to the client a JSON object like this:
{
"total_number_of_pages": 103,
"users": [{}, {}, ..., {}]
}
total_number_of_pages
doesn't really belong here. I could indeed make a special count handler and I like this idea more but perhaps there're better ones. I would like to know how it's implemented in large scale web applications.