title: Adding a REST API to Spring MVC application
body: <p>Assuming an application with a traditional UI based on Spring MVC and Thymeleaf, it seems like there are a few ways to expose a REST API...</p>
  <ol>
  <li><p>Add a completely separate set of Controllers using @RestController - Feels like a lot of duplication, but allows complete separation of UI vs REST logic</p>
  </li>
  <li><p>Use a single Controller for each entity, with a mix of both @ResponseBody methods and ModelAndView methods - Keeps all logic for a given entity in a single place, but requires mixing different concepts</p>
  </li>
  <li><p>Use a single Controller for each entity, use only ModelAndView, and use content negotiation with a JSON view resolver like the MappingJackson2JsonView (<a href="https://spring.io/blog/2013/06/03/content-negotiation-using-views/" rel="nofollow noreferrer">https://spring.io/blog/2013/06/03/content-negotiation-using-views/</a>)</p>
  </li>
  </ol>
  <p>I'm particularly interested in #3 as it feels similar to how Ruby on Rails Controllers work with the respond_to for different content types.</p>
  <p>Is this a common approach / best-practice in Spring applications?</p>
  <p>Would POST and DELETE requests still require separate methods since they may work differently between a REST API vs the UI? (i.e. posting a form vs posting a json entity)</p>
  <p>Would it require separate Exception handling based on whether it was a UI request or API request?</p>