Skip to content

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#9065
marzelin wants to merge 4 commits intonodejs:masterfrom
marzelin:marzelin-http-get-example

Conversation

@marzelin
Copy link
Contributor

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
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.get method that looked like a proper tool for that. But the example was confusing because of res.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 the http.ClientRequest section) that it should be there only if the body won't be consumed in any other manner. But I still didn't know what the resume() method does exactly. So I search further and found that res is an instance of IncomingMessage which implements readable stream. And that's where I found description of readable.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.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations. http Issues or PRs related to the http subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants