Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I am having a problem with my get request with nodejs, what is required as instruction is "
write a program to perform a GET request on the route https://coderbyte.com/api/challenges/json/rest-get-simple and then print to the console the hobbies property in the following format: ITEM1, ITEM2, ...
"

// Output example expected
'running','painting'

What I have tried:

JavaScript
<pre>const https = require('https');

https.get('https://coderbyte.com/api/challenges/json/rest-get-simple', 
(res) => {
  
  res.on('data', (d)=> {
    bv = JSON.parse(d.toString());
    console.log("Hobbies", bv.hobbies);
  }).on('error',(e)=> {
    console.error(e);
  });


});


// output is incorrect as it prints
Hobbies [ 'running', 'coding', 'camping' ]
Posted
Updated 28-Feb-23 19:48pm

1 solution

As per my message from yesterday, you need to do your research first.

There is absolutely nothing wrong with your code when it returns -
Hobbies [ 'running', 'coding', 'camping' ]


Why, just paste the GET THE DATA FROM ARRAY SHOWN AT - https://coderbyte.com/api/challenges/json/rest-get-simple [^] into your browser and this is the data shown -
{"name":"John Smith","age":25,"hobbies":["running","coding","camping"]}
 
Share this answer
 
Comments
Gcobani Mkontwana 1-Mar-23 2:58am    
@Andre Oosthuizen i wonder why from the editor when it compiles that my inputs are incorrect
Andre Oosthuizen 1-Mar-23 3:06am    
I cannot answer that as there are way too many variables at play. One will need to check set-up, controllers, API's, actual code etc etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900