How do I write a Google Cloud Function that will receive a HTTP request and then send a HTTP POST request to a different endpoint?
For example,
I can send the HTTP trigger to my cloud function (https://us-central1-plugin-check-xxxx.cloudfunctions.net/test). I am using
exports.test = function helloWorld(req, res){}
to process the data received.And then I want to send the processed data with a HTTP POST request to a different endpoint.
By far I have tried sending HTTP POST with node-webhooks, request & restler modules but none of them seem to work. Is it because these modules are used in conjunction with exports.test ?
My question is related to this question but the answers didn't help me.
The data being sent to endpoint is in json & Content-type: application/json.
var request = require('request'); //also tried for node-webhook, restler modules
exports.test = function(req, res) {
//processing of received json data from source A.
}
function sendToEndpoint(processed_data) {
let abc = processed_data; //send processed data to source B
request.post({
uri: 'https://example.com',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(abc)
});
}