From the course: Creating Your First Spring Boot Microservice

Unlock the full course today

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

Create RestController HTTP GET methods

Create RestController HTTP GET methods

From the course: Creating Your First Spring Boot Microservice

Start my 1-month free trial

Create RestController HTTP GET methods

- [Instructor] Now let's create two new APIs. One to look up all the ratings for a tour and the other to calculate the average score for all the ratings. I think it's best to hide the implementation of tourRating's entity from the API so we will return a list of tourDto objects. And we will calculate the average by setting the URL with a /average at the end. And then we will return adjacent packet with a key-value pair of the word average and then the actual average score. So we're back in our TourRatingController and I'm just going to paste in the body of these two methods. Because I know it's really thrilling for you guys to watch me type. I'm just going to do my imports. So this first method, getAllRatingsForTour you take the tourId in, verify that it's a tour ID. We're not going to use the return tourValue of verifyTour it's just going to do the lookup and if it's found it's fine if it's not found it'll throw an…

Contents