From the course: Building RESTful Web APIs with Django

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Enabling pagination of querysets in API responses

Enabling pagination of querysets in API responses

From the course: Building RESTful Web APIs with Django

Start my 1-month free trial

Enabling pagination of querysets in API responses

- [Instructor] Sometimes we may have a lot of results to return from the query set in our API response. Django REST framework provides three ways to paginate results: by PageNumber, by Limit OffSet, and by Cursor. The PageNumber pagination defaults to using Django's built-in paginator class and let's API consumers pass in a page number to get a page of results. The LimitOffset pagination is more nuanced and let's API consumers pass in two query parameters. The Limit which controls how many items appear on a page and the OffSet which controls which page appears. The Cursor pagination uses the database cursor for paginating results. The key reason to use this is when you have very large datasets and using the other paginator types would be to inefficient. Now let's add pagination to our product list API view. From REST framework, we import the pagination type we're going to use which is Limit OffSet pagination. And we create our own new pagination subclass ProductsPagination. We set a…

Contents