It's my understanding that with cursor pagination, there are two types of cursor pagination that differ depending on what the cursor represents:
- cursor represents a single point in the dataset
- cursor represents a contiguous batch of the dataset
In this type, the cursor points to a specific point (maybe a record) in a dataset. This is the type used by Facebook and the response looks like this:
{
"data": [ ... ],
"paging": {
"cursors": {
"after": "xyz",
"before": "abc"
},
"next_page": "https://www.example.com/api/cats?after=xyz",
"prev_page": "https://www.example.com/api/cats?before=abc"
}
}
In the above, the before cursor "abc"
represents the beginning of the page, or the point before the first record of the response-set. And after cursor "xyz"
represents that after the last. This means if we wanted to retrieve the next page of results, we would want to get results after the last record of the current page: "xyz"
, or https://www.example.com/api/cats?after=xyz
.
Asking for https://www.example.com/api/cats?before=xyz
or https://www.example.com/api/cats?after=abc
will retrieve the current page. The concept of before and after is needed to differentiate which side of the point you are requesting records from.
In this type, the cursor points to a contiguous batch (or page) of records in a specific dataset. This is the type used by Twitter and the response looks like this:
{
"data": [ ... ],
"paging": {
"cursors": {
"current": "123",
"next": "xyz",
"previous": "abc"
},
"next_page": "https://www.example.com/api/cats?cursor=xyz",
"prev_page": "https://www.example.com/api/cats?cursor=abc"
}
}
Unlike when the cursor represented a single point, these cursors represent whole batches. The concept of before and after don't apply here and we retrieve the correct batch directly using cursor as in: https://www.example.com/api/cats?cursor=xyz
One caveat to losing before and after is that we no longer have a way to refer to the current page. A solution might be to also return the cursor representing the current batch.
The Twitter API link you supplied says this:
throws a link into the ring
https://cloud.google.com/appengine/docs/python/datastore/queries#Python_Query_cursors
The quotes from the above URL best captured my sentiment at the time.
My intent was to support forward, and then backward, navigation of result sets, excluding newly added records. Parameter name were chosen without respect to any particular "Datastore" or implementation.
The API accepts a GET parameter
next_cursor
, which encodes the information to determine the last record sent to the client and that the client would like the next set of results.A not yet implement
previous_cursor
would encodes the information to determine the last record sent to the client and that the client would like the previous set of results.We could assume that we will only support forward-pagination, or as the Twitter API specifies, the previous and next cursors could be contained in the response but only accept a
cursor
param in the requestNot Implemented by the Scripted API