Reputation: 2929
I reviewed request module for node https://github.com/mikeal/request But can't figure out how to proxy POST request to remote server, example
app.post('/items', function(req, res){
var options = {
host: 'https://remotedomain.com',
path: '/api/items/,
port: 80
};
var ret = res;
http.get(options, function(res){
var data = '';
res.on('data', function(chunk){
data += chunk;
});
res.on('end', function(){
var obj = JSON.parse(data);
ret.json({obj: obj});
console.log('end');
});
});
});
Upvotes: 1
Views: 4034
Reputation: 6039
Unless I am missing something from your question, you can just do a simple post, and then do something with the response data:
var request = require('request');
app.post('/items', function(req, res){
request.post('https://remotedomain.com/api/items', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body); // Print the body of the response. If it's not there, check the response obj
//do all your magical stuff here
}
})
Upvotes: 3