Skip to content

Instantly share code, notes, and snippets.

@0xPr0xy
Created February 21, 2013 07:46
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 0xPr0xy/5002984 to your computer and use it in GitHub Desktop.
Save 0xPr0xy/5002984 to your computer and use it in GitHub Desktop.
var express = require('express');
var app = express();
var port = process.env.PORT || 5000;
var request = require('request');
var zlib = require('zlib');
app.listen(port, function() {
console.log("Listening on " + port);
makeRequest();
});
function makeRequest(){
var url = 'https://api.stackexchange.com/2.1/search?pagesize=5&order=desc&sort=activity&intitle=ios development&site=stackoverflow';
var headers = {'Accept-Encoding': 'gzip'};
var response = request(url, headers);
gunzipJSON(response);
}
function gunzipJSON(response){
var gunzip = zlib.createGunzip();
var json = "";
gunzip.on('data', function(data){
json += data.toString();
});
gunzip.on('end', function(){
parseJSON(json);
});
response.pipe(gunzip);
}
function parseJSON(json){
var json = JSON.parse(json);
if(json.items.length){
for(var i in json.items){
console.log(json.items[i].title + '\n' + json.items[i].link);
}
}
}
@eodgooch
Copy link

lines 33 and 37 should be response.on('data' ...

@xsser
Copy link

xsser commented Sep 27, 2016

lice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment