Pagination and sorting
Pagination
Pagination is a technique used to divide numerous results into smaller chunks, or pages, for easier browsing. When using our Mono API, the client can specify two parameters: page_size
and page_number
in our endpoint that list objects. These parameters can be passed as query parameters in the API request.
The page_size
parameter determines the number of results that should be returned in each page. For example, if the page_size
is set to 10, the API will return 10 results per page.
The page_number
parameter determines which page of results should be returned. For example, if the page_number
is set to 2, the API will return the second page of results.
Every list of items returned by the API should include a pagination object with the following structure:
{
"items": [],
"pagination": {
"page_number": 1,
"page_size": 10,
"total_items": 100,
"total_pages": 10
}
}
The items field contains the list of objects returned by the API for the current page. The pagination object contains metadata about the results, including the current page_number
and page_size
, as well as the total_items
and total_pages
.
The total_items
field indicates the total number of objects in the result set, and the total_pages
field indicates the total number of pages required to display all the results. This information can be used by the client to build UI controls for navigating through the pages of results.
Sorting
Sorting is a technique used to rearrange the items in a list in a particular order, either ascending or descending. When using a sorting API, the client can specify a sort parameter in a query string.
The sort parameter should include two fields: type
and field
. The type
field determines the sort order, and can have the values asc
for ascending or desc
for descending. The field
field specifies the field by which the items should be sorted, the values for this field is documented by every endpoint that supports these sorting parameters.
For example, the following query string would sort the items in ascending order by the id field:
?sort[type]=asc&sort[field]=id
Updated almost 2 years ago