I want to write a REST API client with springBoot MVC. The client will send request to the API for data and will show them into the browser. For example, I'll have http://example.com/showItems mapped to itemsController.show method and rendered by an item.html (thymeleaf) template.
My question is where to put the API call and how to deal with the API response. I'm thinking about design, not just make it work. Let also imagine I want to extend to many API call returning different objects.
I'm thinking of several options:
- a WebClient inside the controller. The controller deals with API calls that return an item Object.
- the item class takes care of the API call. And maybe adapting the result for rendering. Different objects have different API calls. Maybe all have injected the same WebClient
- I create an itemService that contains a "DAO", an itemDAO that calls the API and return item Objects. Similarly to DAO repository + models.
I'm not sure which solution to adopt. Is there another common way of doing this in spring, or some other design pattern? Or what could be the pros/cons of each solution?
Aucun commentaire:
Enregistrer un commentaire