request / request-promise-native

The simplified HTTP request client 'request' with Promise support. Powered by native ES6 promises.
ISC License
1.1k stars 63 forks source link

Automatically stringifying the body to JSON in POST operations #51

Closed alfdocimo closed 5 years ago

alfdocimo commented 5 years ago

Hi there!

I've been using this library for node microservices and found out something that I didn't quite understand the other day. Through looking at the docs of request-promise I realized that you can specify that the response of a POST operation to be automatically stringify

var options = {
    method: 'POST',
    uri: 'http://api.posttestserver.com/post',
    body: {
        some: 'payload'
    },
    json: true // Automatically stringifies the body to JSON
};

However, I don't think that is currently supported for request-promise-native. Is that right? Would it be good to have support for that?

Thank you! 😄

analog-nico commented 5 years ago

It is supported actually. But it does two more things in addition to parsing the response which might be the reason why it exerted a behavior that you didn’t expect. See the description in the request options documentation. I hope this helps!