From the course: .NET Microservices for Azure Developers
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Obtaining a single pet in the PetsController - Azure Tutorial
From the course: .NET Microservices for Azure Developers
Obtaining a single pet in the PetsController
- [Instructor] Let's now add another endpoint for returning a single pet instead of the entire list. So here, let's return Task of IActionResult, but this time it's going to be GetById. And of course I need to use HttpGet. And this time I'm going to receive the ID of the pet, and that's why I'm going to add this parameter. And let's do the following. Let's use dbContext and of course pets. And then include, since I want to include the breed information. And then I want to pass Where and this expression. And finally FirstOrDefaultAsync. So this is going to return a single pet. Finally, let's return this with the Ok method. So now we're ready to test this out. You can see that we have both pets and pets that receives the ID. So let's try it out. And here, let's pass say two. And of course this is going to return the correct pet, including the breed data.
Contents
-
-
-
-
Creating and cloning the repo1m 2s
-
(Locked)
Creating your first microservice using ASP.NET Core1m 54s
-
(Locked)
Creating and registering the DbContext for the microservice5m 49s
-
(Locked)
Creating the PetsController and returning the list of pets2m 36s
-
(Locked)
Obtaining a single pet in the PetsController1m 30s
-
(Locked)
Creating a new pet3m 21s
-
(Locked)
Challenge: Implementing BreedsController and validations1m 5s
-
(Locked)
Solution: Implementing BreedsController and validations1m 35s
-
-
-
-
-