Skip to content

Instantly share code, notes, and snippets.

@rehanift
Created October 30, 2011 20:53
Show Gist options
  • Save rehanift/1326429 to your computer and use it in GitHub Desktop.
Save rehanift/1326429 to your computer and use it in GitHub Desktop.
engine.js fetch context
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