Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Is it possible to use JSONStream to read the request of a POST method in a REST API? #158

Open
alejandrofdez-us opened this issue Jul 30, 2018 · 1 comment

Comments

@alejandrofdez-us
Copy link

Any sample of this? Thanks in advance!

@sim2github
Copy link

You can pipe request to parser and use event data

JSONStream.parse([true])
    .pipe(
        request(
            {
                method: 'POST',
                url: this.url.href + '/_bulk_docs',
                headers: this.headers
            },
            function (err, res, body) {
                if (err) {
                    console.log('RESPONSE ERROR:', err)
                    return
                }
                if (res && res.statusCode !== 201) {
                    console.log(res.statusMessage, res.body)
                }
            })
    )
    .on('error', err => {
        console.error('INPUT ERROR:', err)
    })
    .on('data', doc => {
        console.log(doc.toString())
        // or write to other stream e.g. JSONStream.stringify()
    })
    .on('end', () => {
         // Event on end
    })

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants