title: How to POST and retrieve data from a database in R using REST API?
body: <p>I need to call an API within R which will make the request to a database server and fetch the results into an R dataframe.</p>
  
  <p>The API I have is of the form:</p>
  
  <pre><code>http://servername01.home.local/tech-myobjectapi-0.3/myObjectApi/api/v2/Object
  </code></pre>
  
  <p>I also have to pass the body in this JSON format:</p>
  
  <pre><code>    {  
              "resourceName":"treatment_response",
  
              "parameters":
                [
                  {
                    "name":"trial_name",
                    "value":"TRIAL NAME 01"
                  },
                  {
                    "name":"Identifier",
                    "value":"56-8956"
                  }                          
                  ]  
  
            }
  </code></pre>
  
  <p>The header JSON:</p>
  
  <pre><code>ApplicationName : APP_1
  </code></pre>
  
  <p>My R script is:</p>
  
  <pre><code>library(RJSONIO)
  library(RCurl)
  library(httr)
  library("jsonlite")
  
  r &lt;- POST("http://servername01.home.local/tech-myobjectapi-0.3/myObjectApi/api/v2/Object", 
            body = '{  
              "resourceName":"treatment_response",
  
              "parameters":
                [
                  {
                    "name":"trial_name",
                    "value":"TRIAL NAME 01"
                  },
                  {
                    "name":"Identifier",
                    "value":"56-8956"
                  }                          
                  ]  
  
            }' ,
            add_headers("ApplicationName : APP_1")
  )
  
  stop_for_status(r)
  a&lt;-content(r, "text", "application/json", encoding="UTF-8")
  cat(a, file = "test.json")
  x&lt;-fromJSON(file("test.json", "r"))
  mydf&lt;-do.call(rbind, lapply(x$data, data.frame))
  </code></pre>
  
  <blockquote>
    <p>Error in curl::curl_fetch_memory(url, handle = handle) :    Couldn't
    resolve host name</p>
  </blockquote>