Common Concept - Straas/Straas-web-document GitHub Wiki

Basics of Pagination

To start with, there are 2 points StraaS developers need to know about pagination:

  • Different API calls may respond with different defaults. The related default values are specified in the header section of list api.
  • You can specify how many items to receive (up to a maximum of 100); Information about pagination is provided in the Link header of an API call. Two variables are provided, page and per_page, which help client developer to handle the page listing easily. The default value of per_page is 10 if the parameter is not provided.

The following example is a video listing request.

curl -X GET -H "Authorization: Bearer <APP_TOKEN>" "https://app.straas.net/api/v1/app/videos?page=2"

The response header is:

alt-svc: clear
cache-control: max-age=0, private, must-revalidate
content-encoding: gzip
content-type: application/json
date: Fri, 28 Oct 2016 10:07:58 GMT
etag: W/"275a7344f685f39f03b9ef37b2ca4561"
link: <http://app.straas.net/api/v1/app/videos?page=1>; rel="first", <http://app.straas.net/api/v1/app/videos?page=1>; rel="prev", <http://app.straas.net/api/v1/app/videos?page=4>; rel="last", <http://app.straas.net/api/v1/app/videos?page=3>; rel="next"
per-page: 10
server: nginx/1.11.1
srv: 250
status: 200, 200 OK
strict-transport-security: max-age=31536000
total: 31
vary: Accept-Encoding, Accept-Encoding
via: 1.1 google
x-powered-by: Phusion Passenger
x-request-id: 059ccef0-ceaf-469c-9644-522ba73747d3
x-runtime: 0.028714

The header includes the fields, link, per-page and total, which are used for pagination.

link: <http://app.straas.net/api/v1/app/videos?page=1>; rel="first", <http://app.straas.net/api/v1/app/videos?page=1>; rel="prev", <http://app.straas.net/api/v1/app/videos?page=4>; rel="last", <http://app.straas.net/api/v1/app/videos?page=3>; rel="next"
per-page: 10
total: 31
⚠️ **GitHub.com Fallback** ⚠️