Chapter 7. Using pagination in the API


The API paginates responses for collections. This means that while a collection might contain tens or hundreds of thousands of objects, in each web request, only a limited number of results are returned for API performance reasons.

When you receive the result for a collection, something similar to the following appears:

{'count': 25, 'next': 'http://testserver/api/v2/some_resource?page=2', 'previous': None, 'results': [ ... ] }

Procedure

  1. Request the page given by the "next" sequential URL, to get to the next page.
  2. Use the page_size=XX query string parameter to change the number of results returned for each request.

    • The page_size has a default maximum limit of 200, which is enforced when a user tries a value beyond it, for example, ?page_size=1000. However, you can change this limit by setting the value in /etc/tower/conf.d/<some file>.py to something higher. For example, MAX_PAGE_SIZE=1000.
  3. Use the page query string parameter to retrieve a particular page of results:

    http://<server name>/api/v2/model_verbose_name?page_size=100&page=2

The preceding and following links returned with the results set these query string parameters automatically.

Do not request page sizes greater than 200.

The user interface uses smaller values to avoid scrolling.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.