How to print contents on webpage from RESTful web service

I am using a RESTful web service to make a to do list app. I am able to make a GET request and retrieve all of my todos but I don't know how to print them onto my webpage.

Here is the part responsible for making the GET request:

router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
    request({
    url: url, //URL to hit
    qs: {from: 'blog example', time: +new Date()}, //Query string data
    method: 'GET', //Specify the method  
    headers: { //We can define headers too
        'Content-Type': 'MyContentType',
        'Custom-Header': 'Custom Value'
    }
    }, function(error, response, body){
      if(error) {
          console.log(error);
      } else {
          console.log(response.statusCode, body);
      }
});

I am using jade instead of HTML. Running the above code outputs the following into my console.

200 '[{"id":"4017cd30-164e-11e5-9a6f-f52ee4e229e9","data":{"name":"Hello 
world"}},{"id":"e0591080-1656-11e5-955e-271a38c26f32","data":{"name":"get 
groceries"}},{"id":"e97fe620-1656-11e5-955e-271a38c26f32","data":
{"name":"deposit cheque"}}]'

This is what I need to print to webpage. Thanks.

Answers


router.get('/', function(req, res, next) {

    request({
    url: url, //URL to hit
    qs: {from: 'blog example', time: +new Date()}, //Query string data
    method: 'GET', //Specify the method  
    headers: { //We can define headers too
        'Content-Type': 'MyContentType',
        'Custom-Header': 'Custom Value'
    }
    }, function(error, response, body){
      if(error) {
          res.render('index', { title: 'Express', data: []});
      } else {
          res.render('index', { title: 'Express', data: body });
      }

});

In you jade file:

ul
  for item in data
    li= item
  else
    li sorry, no items!

Need Your Help

Preflight OPTIONS request to SOAP service does not work

javascript jquery soap cxf cors

What I want to do: Call a cross-domain SOAP-Service from JavaScript using jQuery with the jQuery Soap plugin (by Remy Blom). (that is, I call $.soap(); in JavaScript)

How do I solve SecurityNegotiationException and InvalidCredentialException in WCF

c# wcf exception networking network-programming

So I've written a small game and wish for the game to be playable over the internet.