Repository navigation
doc: nodejs > http > get > Example KO #37907
Description
Activity
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Mar 25, 2021 Nice catch here!
As docs, it is always desirable to provide a working example. (although the example is illustrative enough for me personally :))/ The entire world is turning into https, there is not so much Public APIs which provides http service without authentication required. Moreover, such service is not guaranteed to work in the future.
Maybe we can spin up a local server to provide JSON service here? It could make things more controllable.
Also, I think this is a good first issue here. Would you like to submit a PR?
Thanks
- addedhttpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
on Mar 25, 2021 Hey there,
Thanks for your response. I didn't had the time to put my hands into the repo's code, so I don't haev a PR to submit sadly :(
(and I'm still kinda neeb with nodeJs :3)The local server idea seems pretty good though ; or else simply switch the whole request to https0
Cheers
Hi,
If no one has taken this up yet, I'll be happy to push a quick fix.
@Ayase-252
Would adding a check for status code301for valid redirections be considered a valid fix for this?
Or, are we looking to host a local server that returns a placeholder json and let http get from the local server instead?The example in question is to demostrate how to fetch a JSON response with "native" Node.js, therefore I prefer to host a very simple http server which outputs a JSON. Something like
const svr = http.createServer((req, res) => { res.writeHead(200, { "content-type": "application/json"}) res.end(`{ "data": "hello world" }`) }) svr.listen(8000)
The
301response from http://nodejs.org/dist/index.json actually redirects you to https version. I'm afraid it is not a valid fix to accommodate 301 response since this is a doc forhttpmodule.Anyway, please feel free to take this 👍
Reacted by Hassaan Pasha- added a commit that references this issue
on Apr 2, 2021 - added a commit that references this issue
on May 1, 2021 - added a commit that references this issue
on May 22, 2026
📗 API Reference Docs Problem
Location
Section of the site where the content exists
Affected URL(s):
Description
Concise explanation of the problem
Provided example doesn't work anymore, returns an error "Request failed. Status code: 301."
The provided url leads to http :
http.get('http://nodejs.org/dist/index.json', (res) => {but said resource get automatically redirected to it's https twin.
In the example, anything other than 200 is thrown away
if (statusCode !== 200)You need to set a new resource in http only (no redirection towards https) as the http module can't handle the https protocol ^^.
Cheers
submit a pull request.