GameWisp uses cursors for pagination. Here's a brief tutorial on how they work.
The GameWisp REST API utilizes Cursors for pagination. Cursors are used to tell the backend from where to start fetching data. They're more efficient than standard pagination for larger data sets and equally as easy to implement.
If an API response is paginated, it will return a cursor
object in its reply. Like so:
{
"result": {
"status": 1,
"message": "Subscribers Retrieved"
},
"data": [
//an array of JSON objects here...
],
"meta": {
"cursor": {
"current": "Ajcd",
"prev": null,
"next": "MjY=",
"count": 1 //the count of objects returned
}
}
}
The cursor
object contains the following properties:
Property | Type | Description |
---|---|---|
current | String | The cursor identifier of the current set of data |
prev | String | The cursor identifier of the last set of data. This isn't automatically calculated, but returned for you if you pass in the current cursor as previous on a subsequent call. |
next | String | The next cursor. Pass this in as the cursor parameter for a subsequent call to get the next set of data. |
count | Integer | The number of objects returned in the response. |
The /channel/subscribers endpoint makes use of cursors for pagination. An example call to that endpoint is as follows:
var params = {
access_token: "CHANNEL_ACCESS_TOKEN",
limit: 1,
order: 'desc',
status: 'active',
include: 'user',
cursor: 'MjY=',
previous: 'Ajcd'
};
$.getJSON('https://gamewisp.com/api/pub/v1/channel/subscribers/', params, function(json) {
console.log(json);
});
The response from the above example will return a cursor object that looks like the following:
{
"result": {
"status": 1,
"message": "Subscribers Retrieved"
},
"data": [
//an array of JSON objects here...
],
"meta": {
"cursor": {
"current": "MjY=",
"prev": "Ajcd",
"next": "MeR=",
"count": 1 //the count of objects returned
}
}
}
If you follow a cursor to a response that returns an empty data object, you've reached the end of the data relevant to your query.