title: Rest types, JSON or HTML forms with the same URL
body: <p>I am trying to create a RESTful service and encounter a type conflict within the application. Right now, I deal with this problem by using two different URLs, but this leads to other problems and doesn't feel right.</p>
  
  <pre><code>// Controller to get a JSON
  @RequestMapping(value = "/stuff/{stuffId}",
          method = RequestMethod.GET,
          produces = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public stuffDto getStuff(@PathVariable String stuffId) {
      return //JSON DTO//
  }
  
  // Controller to get an HTML Form
  @RequestMapping(value = "/stuff/{stuffId}/form", // &lt;- nasty '/form' here
              method = RequestMethod.GET)
  public String getStuffForm(@PathVariable String stuffId, ModelMap model) {
      // Prepares the model
      return "JSP_Form";
  }
  </code></pre>
  
  <p>And on the JavaScript side:</p>
  
  <pre><code>function loadStuffForm(url) {
      $.ajax({
          type : 'GET',
          url : url,
          success : function(response) {
              showStuffForm(response);
          }
      });
  }
  </code></pre>
  
  <p>How can I merge both controllers so it will return the right type of data based on what the client accepts? By default it would return a JSON. I want to add 'text/html' somewhere in the ajax query to get the Form instead. Any idea?</p>