{"_id":"56afdc7d9d32e30d0006d3c5","category":{"_id":"56acd8f95ac4060d0027865e","__v":7,"project":"56acd71213ac890d001c3c7a","version":"56acd71213ac890d001c3c7d","pages":["56ad4897c00d120d00744350","56afce739d32e30d0006d3b5","56afd4573a5b810d00745d77","56afd5049d32e30d0006d3bf","56afdc7d9d32e30d0006d3c5","56afdda49d32e30d0006d3c8","56b136c636d2580d002478d2"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-30T15:38:33.013Z","from_sync":false,"order":2,"slug":"restful-api","title":"REST API"},"githubsync":"","project":"56acd71213ac890d001c3c7a","version":{"_id":"56acd71213ac890d001c3c7d","project":"56acd71213ac890d001c3c7a","__v":15,"createdAt":"2016-01-30T15:30:26.928Z","releaseDate":"2016-01-30T15:30:26.928Z","categories":["56acd71313ac890d001c3c7e","56acd8f113ac890d001c3c81","56acd8f95ac4060d0027865e","56acd93a13ac890d001c3c82","56ad20660ab3c00d00ce3347","56ad356a2a7860170013f714","56ad47eb0ab3c00d00ce334f","56afd523bc304a0d00ace1df","56b29a019621f20d00efb37e","56b657e11bc6970d009feee7","5845cc3c39950c1b002afe77","5845cde163c11b250037967e","5846efd45d064323007b17b4","588604da4674e32300efd160","588627882393d50f00f1322c"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":2,"user":"56acd6caa040860d00ac94a2","parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-01T22:30:21.319Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"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.\n\nIf an API response is paginated, it will return a ```cursor``` object in its reply. Like so:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"result\\\": {\\n    \\\"status\\\": 1,\\n    \\\"message\\\": \\\"Subscribers Retrieved\\\"\\n  },\\n  \\\"data\\\": [\\n    //an array of JSON objects here...\\n  ],\\n  \\\"meta\\\": {\\n    \\\"cursor\\\": {\\n      \\\"current\\\": \\\"Ajcd\\\",\\n      \\\"prev\\\": null,\\n      \\\"next\\\": \\\"MjY=\\\",\\n      \\\"count\\\": 1 //the count of objects returned\\n    }\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThe ```cursor``` object contains the following properties:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"current\",\n    \"0-1\": \"String\",\n    \"0-2\": \"The cursor identifier of the current set of data\",\n    \"1-0\": \"prev\",\n    \"1-1\": \"String\",\n    \"1-2\": \"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.\",\n    \"2-0\": \"next\",\n    \"2-1\": \"String\",\n    \"2-2\": \"The next cursor. Pass this in as the ```cursor``` parameter for a subsequent call to get the next set of data.\",\n    \"3-0\": \"count\",\n    \"3-1\": \"Integer\",\n    \"3-2\": \"The number of objects returned in the response.\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\nThe[ /channel/subscribers](https://gamewisp.readme.io/docs/channelsubscribers) endpoint makes use of cursors for pagination. An example call to that endpoint is as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var params = {\\n\\taccess_token: \\\"CHANNEL_ACCESS_TOKEN\\\",\\n\\tlimit: 1,\\n\\torder: 'desc',\\n\\tstatus: 'active',\\n  include: 'user',\\n  cursor: 'MjY=',\\n  previous: 'Ajcd'\\n};\\n\\n$.getJSON('https://gamewisp.com/api/pub/v1/channel/subscribers/', params, function(json) {\\n    console.log(json);\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThe response from the above example will return a cursor object that looks like the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"result\\\": {\\n    \\\"status\\\": 1,\\n    \\\"message\\\": \\\"Subscribers Retrieved\\\"\\n  },\\n  \\\"data\\\": [\\n    //an array of JSON objects here...\\n  ],\\n  \\\"meta\\\": {\\n    \\\"cursor\\\": {\\n      \\\"current\\\": \\\"MjY=\\\",\\n      \\\"prev\\\": \\\"Ajcd\\\",\\n      \\\"next\\\": \\\"MeR=\\\",\\n      \\\"count\\\": 1 //the count of objects returned\\n    }\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nIf 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.","excerpt":"GameWisp uses cursors for pagination. Here's a brief tutorial on how they work.","slug":"pagination-with-cursors","type":"basic","title":"Pagination with Cursors"}

Pagination with Cursors

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: [block:code] { "codes": [ { "code": "{\n \"result\": {\n \"status\": 1,\n \"message\": \"Subscribers Retrieved\"\n },\n \"data\": [\n //an array of JSON objects here...\n ],\n \"meta\": {\n \"cursor\": {\n \"current\": \"Ajcd\",\n \"prev\": null,\n \"next\": \"MjY=\",\n \"count\": 1 //the count of objects returned\n }\n }\n}", "language": "json" } ] } [/block] The ```cursor``` object contains the following properties: [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-0": "current", "0-1": "String", "0-2": "The cursor identifier of the current set of data", "1-0": "prev", "1-1": "String", "1-2": "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.", "2-0": "next", "2-1": "String", "2-2": "The next cursor. Pass this in as the ```cursor``` parameter for a subsequent call to get the next set of data.", "3-0": "count", "3-1": "Integer", "3-2": "The number of objects returned in the response." }, "cols": 3, "rows": 4 } [/block] The[ /channel/subscribers](https://gamewisp.readme.io/docs/channelsubscribers) endpoint makes use of cursors for pagination. An example call to that endpoint is as follows: [block:code] { "codes": [ { "code": "var params = {\n\taccess_token: \"CHANNEL_ACCESS_TOKEN\",\n\tlimit: 1,\n\torder: 'desc',\n\tstatus: 'active',\n include: 'user',\n cursor: 'MjY=',\n previous: 'Ajcd'\n};\n\n$.getJSON('https://gamewisp.com/api/pub/v1/channel/subscribers/', params, function(json) {\n console.log(json);\n});", "language": "javascript" } ] } [/block] The response from the above example will return a cursor object that looks like the following: [block:code] { "codes": [ { "code": "{\n \"result\": {\n \"status\": 1,\n \"message\": \"Subscribers Retrieved\"\n },\n \"data\": [\n //an array of JSON objects here...\n ],\n \"meta\": {\n \"cursor\": {\n \"current\": \"MjY=\",\n \"prev\": \"Ajcd\",\n \"next\": \"MeR=\",\n \"count\": 1 //the count of objects returned\n }\n }\n}", "language": "json" } ] } [/block] 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.