title: Go Gin-Gonic, get text from POST request
body: <p>I'm starting to develop a <strong>REST</strong> API using <strong>Go</strong> and package <strong>Gin-Gonic</strong>. The idea is to create a REST API that receives POST requests in a JSON format and redirects this call to another application (also a API). Here is a piece of code:</p>
  <pre><code>package main
  
  import (
      &quot;fmt&quot;
  
      &quot;github.com/gin-gonic/gin&quot;
      &quot;net/http&quot;
  )
  func main() {
      r := gin.Default()
      r.GET(&quot;/status&quot;, func(c *gin.Context) {
          c.String(200, &quot;on&quot;)
      })
  
      r.GET(&quot;/user/:name&quot;, func(c *gin.Context) {
          name := c.Param(&quot;name&quot;)
          c.String(http.StatusOK, &quot;Hello %s&quot;, name)
      })
  
      r.GET(&quot;/user/:name/:action&quot;, func(c *gin.Context) {
          name := c.Param(&quot;name&quot;)
          action := c.Param(&quot;action&quot;)
          message := name + &quot; is &quot; + action
          c.String(http.StatusOK, message)
      })
  
      r.POST(&quot;/foo&quot;, func(c *gin.Context) {
          fmt.Printf(&quot;%s&quot;, &quot;At least I got here&quot;)
          message := c.PostForm() //???
          c.JSON(200, gin.H{&quot;status&quot;: message}) //???
      })
      r.Run(&quot;:8080&quot;) // listen an
  }
  </code></pre>
  <p>At function <code>r.Posts(&quot;/foo&quot;,...)</code> I would like <code>c.JSON</code> to send me back the full JSON that I sent:</p>
  <pre><code>curl -H &quot;Content-Type: application/json&quot; -X POST -d '{&quot;user&quot;:&quot;xyz&quot;,&quot;password&quot;:&quot;xyz&quot;}' http://localhost:8080/foo
  </code></pre>
  <p>I've seen examples where they bind the JSON file by creating a struct with the same structure as the input JSON (check Gin-Gonic examples at <a href="https://github.com/gin-gonic/gin" rel="nofollow noreferrer">https://github.com/gin-gonic/gin</a> ). However I only need to resend the full string without taking care of the format. Any ideas?</p>