Skip to content

Instantly share code, notes, and snippets.

@cburgdorf
Last active December 22, 2015 01:48
Show Gist options
  • Save cburgdorf/6398795 to your computer and use it in GitHub Desktop.
Save cburgdorf/6398795 to your computer and use it in GitHub Desktop.
var express = require("express");
var app = express();
var http = require("http");
var url = require('url');
var gunzip = require('zlib').createGunzip();
app.use(express.logger());
var http = require("http");
var url = require('url');
var gunzip = require('zlib').createGunzip();
app.get('/foo', function(request, response) {
var params = '{}';
var dataURL = url.parse('http://api.stackoverflow.com/1.1/users');
var headers = {
"accept-charset" : "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
"accept-language" : "en-US,en;q=0.8",
"accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
"accept-encoding" : "gzip,deflate",
};
var options = {
hostname: dataURL.hostname,
port: dataURL.port || 80,
path: dataURL.path,
method: 'GET',
headers: headers
};
console.log('foo');
http.request(options, function(res) {
var body = '';
res.pipe(gunzip);
gunzip.on('data', function (data) {
body += data;
});
gunzip.on('end', function() {
console.log(JSON.parse(body));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment