Re: REST API

36 views
Skip to first unread message

Zlatko

unread,
Apr 30, 2016, 10:04:46 PM4/30/16
to nodejs


On Wednesday, April 27, 2016 at 5:05:43 PM UTC+2, Sirine Ibn Fraj wrote:
Hello everyone ,
 
I am trying to retrieve data from a REST API in the server side (*.js) and display it in my view (*.jade) 
 

I was able to get the data but was not able to send it to the view . 
This is how my code looks like : 


 var reqGet = https.request(optionsget, function(res) {
        console.log("statusCode: ", res.statusCode);
          res.on('data', function(d) {
          console.info('GET result:\n');
            
            BugData =d ;
            console.log(d);  
            
        }); 
    
    }); 
     
  reqGet.end();


BugData (was defined before )is the variable i am trying to send to the view but for some reasons it is empty and does not contain the variable 'd' 


Does anyone know why or how can i solve this ? 



I will assume that your console.log(d) line displays expected results.

But there's another question: where is your jade and and how do you call the render function? Without seeing those, especially the part where you call render (together with the BugData part), we cannot help you.
 

Nainterceptor

unread,
Apr 30, 2016, 10:04:46 PM4/30/16
to nodejs
Hi,

Where is your render ? I think the good place would be in the 'end' event of your res var. Else, at the tick of your render, you don't have the result of your request.

Regards,
Gaël


Le mercredi 27 avril 2016 17:05:43 UTC+2, Sirine Ibn Fraj a écrit :
Hello everyone ,
 
I am trying to retrieve data from a REST API in the server side (*.js) and display it in my view (*.jade) 
 

I was able to get the data but was not able to send it to the view . 
This is how my code looks like : 


 var reqGet = https.request(optionsget, function(res) {
        console.log("statusCode: ", res.statusCode);
          res.on('data', function(d) {
          console.info('GET result:\n');
            
            BugData =d ;
            console.log(d);  
            
        }); 
    
    }); 
     
  reqGet.end();


BugData (was defined before )is the variable i am trying to send to the view but for some reasons it is empty and does not contain the variable 'd' 


Does anyone know why or how can i solve this ? 
Thanks 
Reply all
Reply to author
Forward
0 new messages