How can I make HTTP POST call to a server using array of request-promise objects where URL is same, only data is different each time.
I have array of objects that need to be POST'ed to a server one by one, independently. I created request promise's array and then promise.all () but failed. However, single object (not using array) works.
Ex: 1. Previous functionality, with 1 object, I use -
var request = require("request-promise")
options.body ={ "name" : "sdsd"}
request (options).then(...).catch(..) -> it works
2. Now with many objects in array, I created objectsArr[], then I use promise.all() or q package, q.all (), it fails with error message from external server, saying invalid json/JSON parsing error.
objArr[] =[{"name":"dsd"},
{{"name":"dsd"},}]
var reqPromises[];
objArr.forEach(function(obj){
options.body= obj
reqPromises.push(request(options)
}
then->
q.all(reqPromise).then(..).catch(..)
Even if object Array has just 1 object, it is an array structure which is causing issues. I do not know how it is working, if it is trying to make 1 http request with arrays in json and henec failing. If in loop, means making multiple POST requests, which I want, it should work.
Please suggest the right approach. Also if any better way to debug and see what JSON is going to server? I use postman to call my local application which talks and sends json to external server. Usually console/log statements are useful but with request/promises/chaining, its hard to debug. :-(