RainingChain
RainingChain

Reputation: 7746

NODEJS: How to extract the "real" message with HTTP.get()

This is what I got so far. I do receive a response from http.get(). However, the response called res has many, many attributes and I can't find where the useful information is...

Everywhere I check, the only thing people mention is res.statusCode, but that's not really what I'm looking for.

This is the only information I have with the API. http://services.runescape.com/m=rswiki/en/Grand_Exchange_APIs

This is the JSON I want to have as a variable: http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=555

Thanks.

var express = require('express');  
var http = require('http');
var https = require("https");
var app = express(); 
var serv = http.createServer(app); 

serv.listen(3000);

app.use(express.static(__dirname + '/public')); 
app.get('/', function (req, res) { 
    res.sendfile(__dirname + '/index.html'); 
});

http.get('http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=555', function(res) {
    console.log(res.statusCode); //200
    console.log(res); //BIG OBJECT

            //var whatIWant = res.?????
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});

Upvotes: 0

Views: 139

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146084

You need to stream the response body with the stream interface using the "data" and "end" events. There are plentiful examples on the web. You may also want a more convenient library that will do this for you such as request.js or superagent.js.

Upvotes: 1

Related Questions