Created
December 23, 2013 14:44
-
-
Save Nedudi/8098281 to your computer and use it in GitHub Desktop.
send request from node.js server
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 generator_port = require('./config').generator.port, | |
http = require('http'), | |
extend = require('util')._extend; | |
module.exports = { | |
_commonOptions: { | |
port: generator_port, | |
headers: { | |
accept: 'application/json' | |
} | |
}, | |
_requestCallback: function(callback) { | |
return function(response) { | |
var result = ''; | |
response.on('data', function(chunk) { | |
result += chunk; | |
}); | |
response.on('end', function() { | |
callback(JSON.parse(result)); | |
}); | |
}; | |
}, | |
getStructureId: function(callback) { | |
http.request( | |
extend({ path: '/?get=structure_id' }, this._commonOptions), | |
this._requestCallback(callback) | |
).end(); | |
}, | |
getStructureRevisionId: function(structure_id, callback) { | |
http.request( | |
extend({ path: '/?get=revision_id&structure_id=' + structure_id }, this._commonOptions), | |
this._requestCallback(callback) | |
).end(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment