fluentnode
Version:
Fluent apis for node (based on the concepts used in C#'s FluentSharp
53 lines (43 loc) • 1.22 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var Server, http, https, url;
http = require('http');
https = require('https');
url = require('url');
Server = http.Server;
String.prototype.http_Status = function(callback) {
return http.get(this._str(), function(res) {
return callback(res.statusCode);
});
};
String.prototype.http_With_Options = function(options, callback) {
var engine, req;
url = url.parse(this._str());
engine = url.protocol === 'https:' ? https : http;
options.hostname = options.hostname || url.hostname;
options.port = options.port || url.port;
options.path = options.path || url.path;
options.method = options.method || 'GET';
req = engine.get(options, function(res) {
var data;
data = '';
res.on('data', function(chunk) {
return data += chunk;
});
return res.on('end', function() {
return callback(null, data, res);
});
});
req.on('error', function(err) {
return callback(err, null, null);
});
return req;
};
/*options =
hostname: @,
port: port,
path: '/',
method: 'GET'
console.log @.str()
*/
}).call(this);