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. :-(
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/307c86d0-33d3-4bbf-8130-7056b4d0e749%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.