First a disclaimer – I am very new to programming. This project is for what's more or less a capstone, and we're working in the Spring Boot framework (Java language, Thymeleaf views).
The overall gist of my program is this: a user fills out a form, and those parameters are used to make a call to the Yelp Fusion API.
I spent a lot of time figuring out how to make the API call, and sort of neglected to think about where to do it. It's currently in my Controller class, but now I'm not so sure if that's the best idea – maybe it should go in a Model or even a DTO? I'd appreciate any insight, as the general internet seems to be conflicted.
Here's the link to the repository on GitHub if that helps.
Thanks!
 
                        
It is preferred to make any client calls or write business logic for the API in the Service layer.
In your case, you can create a service package and create some interface
YelpClientCallService.javawhich is autowired in your controller, and a classYelpClientCallServiceImpl.javathat implements theYelpClientCallService.javainterface. Now, you can call the client API from this class and then perform business logic on the response received, or you can just return the response to the controller.You can also annotate the service class as
@Serviceinstead of@Component. It is just a special name for@Componentand will help in classification. For more details on package structure in Springboot you can check the below resources.