If you return resp , it looks like you forgot that the request is asynchronous. Try instead:
var rest = require('restler'); var getResp = function(url){ rest.get(url).on('complete', function(response){ console.log(response); }); }; getResp('http://google.com/');
Due to its asynchronous nature, it prefers to pass the value to the receiving callback. Take this small example:
var rest = require('restler'); // process an array of URLs ['http://google.com/', 'http://facebook.com/'].forEach(function(item) { getResp(item); }); function getResp(url){ rest.get(url).on('complete', function(response){ processResponse(response); }); }; // data will be a Buffer function processResponse(data) { // converting Buffers to strings is expensive, so I prefer // to do it explicitely when required var str = data.toString(); }
Once the data arrives, you will be able to transfer it, like any other variable.
source share