Pagination 2019-09-09T09:47:16+08:00

Pagination

Certain API can return millions of results that cannot be returned all at once in a single response. Pagination separates the results into pages in which the number of records displayed in each page is defined by the pagesize query parameter. This provides a means to move backwards and forwards through these pages.

To retrieve paginated results, you are required to pass parameter count in the initial query. The response will contain _total_pages which gives total number of pages of the result set. _total_pages and pagesize have this relationship: _total_pages = ceil(total_objects_num / pagesize)

The page parameter controls which page will be returned from the endpoint.

Given below are all the query parameters supported in our API service. If pagesize and page are not given in the query string, a maximum of first 100 objects will be returned.

ParameterRequiredDescriptionTypeFilter TypeExample
pageoptionalThe page to be retrieved, starting from 1. Page 1 will be returned if not specified.querysimple1
pagesizeoptionalThe maximum number of objects that may be returned. Value ranges from 1 to 100, default is 100.querysimple10
countoptionalReturn total number of records and pages of the dataset in a response.query

Examples

Suppose you want to obtain the list of courses offered in academic year 2016/2017. You initially pass parameter count to the endpoint and retrieve total number of pages.

Request

https://api.data.um.edu.mo/service/academic/courses/v1.0.0/all?year=2016&count

Response (truncated)

{
  "_embedded": [
    {
      "_id": "5ac40856e7940a931a02d06a",
      "courseCode": "PORT898",
      "sem": 2,
      "year": 2016,
      "sections": [
        {
          "sectionCode": "001",
          "instructors": [
            {
              "salutation": "Dr.",
              "name": "ANA PAULA BATISTA MARQUES CLETO DE OLIVEIRA GODINHO"
            },
            {
              "salutation": "Prof.",
              "name": "MARIA JOSÉ DOS REIS GROSSO"
            }
          ]
        }
      ],
      "courseTitleEng": "DOCTORAL THESIS"
    },
    ...
  ],
  "_size": 2092,
  "_total_pages": 21,
  "_returned": 100
}

The first page with 100 objects is returned. To get the next 100 results, perform the same request, but set the page value to 2.

Request

https://api.data.um.edu.mo/service/academic/courses/v1.0.0/all?year=2016&page=2

Response (truncated)

  "_embedded": [
    {
      "_id": "5ac40845e7940a931a01eaa3",
      "courseCode": "SOCB121",
      "sem": 2,
      "year": 2016,
      "sections": [
        {
          "sectionCode": "001",
          "classForDetails": "Class for :n - FSS - SOC11<br/>",
          "instructors": [
            {
              "salutation": "Prof.",
              "name": "KUO SHIH-YA"
            }
          ],
          "schedules": [
            {
              "day": 2,
              "componentType": "L",
              "timeFrom": "14:30:00",
              "timeTo": "15:45:00",
              "room1": "E22-3002"
            },
            {
              "day": 5,
              "componentType": "L",
              "timeFrom": "14:30:00",
              "timeTo": "15:45:00",
              "room1": "E22-3002"
            }
          ]
        }
      ],
      "courseTitleEng": "SOCIAL RESEARCH METHODS",
      "courseTitleChi": "社會研究方法"
    },
     ...
  ],
  "_returned": 100
}

If you want to retrieve 10 objects in each API call, you can make a request like this:

Request

https://api.data.um.edu.mo/service/academic/courses/v1.0.0/all?year=2016&pagesize=10

Response (truncated)

{
  "_embedded": [
    {
      "_id": "5ac40856e7940a931a02d06a",
      "courseCode": "PORT898",
      "sem": 2,
      "year": 2016,
      "sections": [
        {
          "sectionCode": "001",
          "instructors": [
            {
              "salutation": "Dr.",
              "name": "ANA PAULA BATISTA MARQUES CLETO DE OLIVEIRA GODINHO"
            },
            {
              "salutation": "Prof.",
              "name": "MARIA JOSÉ DOS REIS GROSSO"
            }
          ]
        }
      ],
      "courseTitleEng": "DOCTORAL THESIS"
    },
    ...
  ],
  "_returned": 10
}