doc: better example for http.get#9065
Closed
marzelin wants to merge 4 commits intonodejs:masterfrom
marzelin:marzelin-http-get-example
Closed
doc: better example for http.get#9065marzelin wants to merge 4 commits intonodejs:masterfrom marzelin:marzelin-http-get-example
marzelin wants to merge 4 commits intonodejs:masterfrom
marzelin:marzelin-http-get-example
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
Affected core subsystem(s)
doc
Description of change
I wanted to get some JSON data using Node.js, so I searched the documentation and found
http.getmethod that looked like a proper tool for that. But the example was confusing because ofres.resume()method. My first thought was that it needs to be at the end of every http.get callback after the code for consuming the response body. But after some research I found (in thehttp.ClientRequestsection) that it should be there only if the body won't be consumed in any other manner. But I still didn't know what theresume()method does exactly. So I search further and found thatresis an instance ofIncomingMessagewhich implements readable stream. And that's where I found description ofreadable.resume().I've learnt a lot from this experience, but what I really wanted was get things done and fetch JSON.
I propose replacing current example with the one that presents the most common use of that method: getting data. Also, I added information about the type of object being passed to the callback and necessity of consuming response data in it.