In more robust applications where a table can have millions of records, it is important to implement paging in a REST API. I have seen in some projects two ways to return paging information (page number, page size, sort order, etc.)
In the body of the answer
- The pagination information stays in the body, such as totalPages, totalElements, size, number , etc.
- The element list is wrapped in a
content
array, part of the returned page object;
In the response header
- The paging information is header, such as totalPages, totalElements, size, number, etc.
- The list of elements is the returned array;
Given the design of a REST API, what is the correct way to pass the paging data in the response?