Created
February 21, 2013 07:46
-
-
Save 0xPr0xy/5002984 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lice!