title: GET Method to return HTML and POST to JSON
body: <p>Using Java and Spring Boot</p>
  <p>I am new to Java and Spring,
  working on a test to create a GET and POST APIs</p>
  <p>I need to create a GET that should return HTML that contains:
  Tags  ...  where I can paste a code snippet;</p>
  <p>Then take this code snippet and pass it to POST Method.</p>
  <p>The GET method is:</p>
  <pre><code>@GetMapping(value = &quot;/code/new&quot;, produces = MediaType.TEXT_HTML_VALUE)
  
        public String getNewAsHTML() {
            return &quot;index&quot;;
  }
  </code></pre>
  <p>The POST method is :</p>
  <pre><code>@PostMapping(value = &quot;/api/code/new&quot;, consumes = &quot;application/json&quot;)
      public String newPostedCode(@RequestBody String code) {
          //  return new ResponseEntity(new CodeSharingPlatformController(), HttpStatus.OK);
          newCode.setCode(code);
          newCode.setDate(new Date());
          return code;
      }
  </code></pre>
  <p>and the HTML Page is:</p>
  <pre><code>&lt;!DOCTYPE  html&gt;
  
  
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
      &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script&gt;
      function send() {
      let object = document.getElementById(&quot;code_snippet&quot;).value;
  
      let json = JSON.stringify(object);
  
      let xhr = new XMLHttpRequest();
      xhr.open(&quot;POST&quot;, '/api/code/new', false);
      xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
      xhr.send(json);
  
      if (xhr.status == 200) {
   alert(&quot;Success!&quot;);
      }}
  &lt;/script&gt;
  &lt;textarea id=&quot;code_snippet&quot;&gt;&lt;/textarea&gt;
  &lt;button id=&quot;send_snippet&quot; type=&quot;submit&quot; onclick=&quot;send()&quot;&gt;Submit&lt;/button&gt;.
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>when I try to write something inside the textarea (e.g: &quot;This is my text&quot;)
  the returned text in &quot;code&quot; object is:</p>
  <pre><code>&quot;code&quot;: &quot;\&quot;This is my text\&quot;&quot; 
  </code></pre>
  <p>(this is how it appears in Postman)</p>
  <p>I need to only return the text written inside the textArea.</p>