needle icon indicating copy to clipboard operation
needle copied to clipboard

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

Open naman1303 opened this issue 4 years ago • 1 comments

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 avatar Mar 24 '20 07:03 naman1303

Issue Identified, Solution Needed

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

Instead of array of two objects

{"$or":[{"requestor_id":"alice" } , { "service_provider":"alice"}]}

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

{"or":[{"requestor_id":"alice" , "service_provider":"alice"}]}

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

naman1303 avatar Mar 24 '20 11:03 naman1303