From the course: Building and Securing RESTful APIs in ASP.NET Core
Create a Collection class - ASP.NET Core Tutorial
From the course: Building and Securing RESTful APIs in ASP.NET Core
Create a Collection class
- [Instructor] Unless your REST API is very simple, it'll need to return more than just single resources. The ION spec defines a collection as a value object where the value property is an array of items that are resources. We can model this in our API by creating a new collection class that inherits from resource. In the models folder I'm gonna create a new class called collection of T. This class will be generic so it can handle any type of resource. We'll inherit from the base resource class. And the only additional property we need here is an array of items of type T called value. Next we'll create and return one of these collections from a controller.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.