But you are showing me how to use the rest controller, read the doc. This I know, but that I don't know is if it's possible to use the same controller for the api and for the application. This would say that with a same action, it's possible to detect if the response should be a json or for a view of my application.
it is good practice to separate your API from your interactive part of the website. Your API also need to follow different design rules, for example towards versioning, that makes mixing functionality difficult.