tomas / needle

Nimble, streamable HTTP client for Node.js. With proxy, iconv, cookie, deflate & multipart support.
https://www.npmjs.com/package/needle
MIT License
1.63k stars 236 forks source link

query : how to handle nesting in body section of post method #302

Open naman1303 opened 4 years ago

naman1303 commented 4 years ago

Hi Team,

I have started using 'needle' recently instead of 'request' module. One of the API call (to select data from database) includes complex input:

  1. Database model - simple string
  2. Database input - object or array of objects (with $or, $and operators)

For e.g.

let options = {
    json: true,
    model: "SampleModel",
    _**input: {
                $or: [
                    { where_field1: 'abc' },
                    { where_field2: '123' }
                ]
            }**_
}

'request' was able to handle it properly and fetch the data. But needle gets stuck during the call.

If I pass it a simple object, like shown below, it works.

_**input: { where_field1: 'abc' }**_

How to handle it?

naman1303 commented 4 years ago

Issue Identified, Solution Needed

I looked at the server logs (of API which is being called):

Instead of array of two objects

{\"$or\":[{\"requestorid\":\"alice\" } , {_ \"service_provider\":\"alice\"}]}

It is coming as array of single object, so no output.

{\"or\":[{\"requestorid\":\"alice\" **,_** \"service_provider\":\"alice\"}]}

** Input is being passed properly to the API call as I have mention in the above thread .