From the course: Advanced Web APIs with ASP.NET Core 8

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Paginating items

Paginating items

- [Instructor] When our API just returns too many items, we could consider splitting the data returned up into pages, providing the client with an easy means to just retrieve some of those products in our case. And of course, we offer the ability to go back and forth. There are several ways how this could be done, but here's my proposal. First of all, we update the API so that there are two query string parameters added, Size and Page. So users can tell the API which page to return and what size a page has. What does that mean in code? So here we have page=2, but if we have an arbitrary page number and we start at page 1, basically what that means in code is, if I'm on page, say, 5, I have to skip the first four pages. And therefore, if we have a page query string parameter, we just skip the size of a page times the page number minus 1. For page=2, we have to skip one page. For page=5, we would need to skip four pages. However, after skipping those elements, I only need to return one…

Contents