Pagination
All services should support pagination from the start, even though the dataset is small. It is harder to add it later on as it would introduce breaking changes to the service interface.
Pagination should be implemented using Cursor as a page reference. Cursor pagination solves the missing or duplication of data problems that the typical offset method has. Cursor pagination returns a cursor in the response, which is a pointer to a specific item in the dataset. This pointer needs to be based on an unique sequential field (or fields).
When implementing a cursor pagination the response object should follow this interface:
The name of the data fields is arbitrary, and the developer is free to choose more descriptive name like in the following example:
PageInfo
The PageInfo
contains details about the pagination. It should follow the interface:
Pagination Query parameters
For an API to support pagination it needs to support the following query parameters:
limit
- Limits the number of results in a request. The server should have a default value for this field.before
- The client provides the value ofstartCursor
from the previous responsepageInfo
to query the previous page oflimit
number of data items.after
- The client provides the value ofendCursor
from the previous response to query the next page oflimit
number of data items.
The client only sends either before
or after
fields in a single request indicating if it wants the previous or next page of data items.
Monorepo library
Last updated
Was this helpful?