From the course: Creating Your First Spring Boot Microservice

Unlock the full course today

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

Create RestController HTTP POST method

Create RestController HTTP POST method

From the course: Creating Your First Spring Boot Microservice

Start my 1-month free trial

Create RestController HTTP POST method

- [Instructor] Now let's implement an API to create a TourRating. But can all the attributes of a TourRating be sent in the request body? Well, let's look at TourRating. We have a integer score and a string comment, yeah that's fine sending on a HTTP payload. Let's look at TourRatingPk. Ah, so we have a tour, which is a type tour and a customer ID, which is integer. Customer ID is fine but I don't think a client would want to send an entire tour as part of the request body, they would likely just use a tour identifier. So we should create a data transfer object to encapsulate the request body. And that's what I've done in RatingDto. So in this web packet I have RatingDto and the attributes are score, a comment, and a customer ID. We don't have a tour ID in here. And that's because that's going to be a parameter on the URL. So we can apply Java validations here. The minimum score is zero, the maximum score is five.…

Contents