tomas / needle

Nimble, streamable HTTP client for Node.js. With proxy, iconv, cookie, deflate & multipart support.

Home Page:https://www.npmjs.com/package/needle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

naman1303 opened this issue · 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?

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 .