Thursday, 4 May 2017

nodejs unirest post request - how to post complex rest / json body

Following is the unirest code I am using to post simple requests.

urClient.post(url)
    .header('Content-Type', 'application/json')
    .header('Authorization', 'Bearer ' + token)
    .end(
        function (response) {

        });

But now its required to send a complex json body with the POST call as shown below:

{
  "Key1": "Val1",
  "SectionArray1": [
    {
      "Section1.1": {
        "Key2": "Val2",
        "Key3": "Val3"
      }
    }
  ],
  "SectionPart2": {
        "Section2.1": {
            "Section2.2": {
                "Key4": "Val4"
            }
        }
    }
}

How could this be done? What's the appropriate syntax to do this?



via StillNestling

No comments:

Post a Comment