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

Unlock the full course today

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

Return all resources in a collection

Return all resources in a collection - ASP.NET Core Tutorial

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

Start my 1-month free trial

Return all resources in a collection

- [Narrator] Let's implement the get rooms route on the rooms controller. I'm gonna rename this method to get all rooms, just to be a little bit more clear about what it does. I used control RR in visual studio to rename it. Since we know this is gonna produce a 200 OK, we can add produces response type 200, and I need to make this async now. This will return a task of action results. The actual response type is gonna be collection of room. Inside this method, we'll call a new service method that we need to write, say var rooms await the room service, get all, or say get rooms, async, we'll need to write that method. Then we'll just build up a collection response. We'll say var collection equals new collection of room. The self link will be a link dot to just this method, get all rooms. And the value's gonna be what we get back from the room service get rooms async, just dot rooms dot to array. The very end here, we need to return this collection. All right, we have some changes we…

Contents