Created
October 30, 2011 20:53
-
-
Save rehanift/1326429 to your computer and use it in GitHub Desktop.
engine.js fetch context
This file contains 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 fetch = function(resource, options, callback){ | |
var url = require("url"); | |
var http = require("http"); | |
var parsed_url = url.parse(resource); | |
var http_options = { | |
host: parsed_url.hostname, | |
port: parsed_url.port || 80, | |
path: parsed_url.pathname + (parsed_url.search || "") + (parsed_url.hash || ""), | |
method: options.method || "GET" | |
}; | |
var req = http.request(http_options, function(res){ | |
var body = ""; | |
res.on("data", function(chunk){ | |
body += chunk; | |
}); | |
res.on("end", function(){ | |
callback(body); | |
}); | |
}); | |
req.end(); | |
}; | |
fetch("http://involver.com/", {}, function(response){ | |
console.log(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment