From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

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

Add navigation to paged collections

Add navigation to paged collections - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Add navigation to paged collections

- [Instructor] If we want our paged collection responses to truly satisfy the HATEOAS constraint, they should include navigation properties that allow the client to move through the pages by following links on the pages. The PagedCollection class already includes these navigation properties. The next step is to write some code that will automatically populate these links. I'll make a new static method at the top of this class called, public static PagedCollection of T, Create, and this'll take a self link, an array of items, an int size for the total size of the collection, and an instance of PagingOptions. And all this method is gonna do is create a new PagedCollection of T, and copy over these items, to say Self equals self, Value equals items, Size equals size, Offset comes from the pagingOptions dot Offset, Limit comes from the pagingOptions dot Limit, the First link is just self, and then for the next, previous, and last links, we need to write some new methods. We'll say Next…

Contents