4
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 pagination information (page number, page size, ordering, etc)
In the body of the answer
- Pagination information stays in the body, such as totalPages, totalElements, size, number, etc.;
- The list of elements is packaged in an array
content
, being part of the returned page object;
In the answer header
- Pagination information gets header, such as totalPages, totalElements, size, number, etc.;
- The list of elements is the main array returned;
Taking into account the design of a REST API, what is the correct way to pass pagination data in Sponse?
This is a delusion of complex design, I do not believe that there is a "correct" answer... That being said, there is a tendency to frame pagination in the HATEOAS standard with information about pagination in the body, as well as links to other pages (first, next, previous, last). This pattern is very practical, especially when the client has the respective methods next, Previous, etc implemented for you
– Anthony Accioly