'How do I use @GetMapping properly (SpringBoot)?
Basically, I'm using spring boot and thymeleaf to create a web site for a restaurant catering (just an exercise for a class) where chefs offer buffets and where each buffet is made up of different dishes with different ingredients (sorry for my english).
My question is: should I use @GetMapping("/chef/{id}/buffets") to indicate the buffets made by a chef?
Or should I just use ("/buffet")? Because for the ingredient's controller I will end up using ("/chef/{id}/buffet/{id}/plate{id}/ingredients") and it looks weird, but I dont think I can do it any other ways.
Also, how do I write it in thymeleaf to link chef and his own buffets etc.? Thank you for your help.
UPDATE: ok but now i'm stuck. let's say I use this code to get a chef in particular:
@GetMapping("/chef/{id}")
public String getChef(@PathVariable("id")Long id, Model model) {
Chef chef = cs.findById(id);
model.addAttribute("chef",chef);
return "chef.html";
}
How would the function to get all the buffets made by that chef be?
Solution 1:[1]
The question is not about how to use @GetMapping() in Spring but to understand REST URI API.
For your type of problem, you will need to expose a URI like you said above :
"/chef/{chef_id}/buffet/{buffet_id}/plate/{plate_id}/ingredients"
The reason being, as you mentionned above, is each chef as many buffets and each buffet has many plates and each plate has many ingredients.
[chef] 1---* [buffet] 1---* [plate] 1---* [ingredients]
Exposing a URI such as /buffet will have to list all the buffets for ALL the chefs in your database
Here's a link to a good article about good practices for REST API https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
