Consumir o serviço da Web JSON a partir do pedido Nó / Expresso?
Eu tenho o seguinte caminho:
exports.index = function(req, res){
res.render('index', { title: 'Express' });
};
Gostaria de chamar o seguinte serviço da web:http://ergast.com/api/f1/current/last/results e diga para retornar JSON.
Eu tentei algo parecido com isto no pedido de índice, mas ele erros:
var options = {
host: 'ergast.com',
port: 80,
path:'/api/f1/current/last/results.json'
};
http.get(options, function(response) {
response.setEncoding('utf-8');
console.log("Got response: " + response.statusCode);
var data = JSON.parse(response);
}).on('error', function(e) {
console.log("Got error: " + e.message);
}).on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
Eu estou supondo que provavelmente estou perdendo o ponto em algum lugar.
obrigado