Node.js 谷歌云功能调用托管在谷歌应用程序引擎上的URL

Node.js 谷歌云功能调用托管在谷歌应用程序引擎上的URL,node.js,firebase,google-cloud-functions,Node.js,Firebase,Google Cloud Functions,我有一个firebase数据库,我希望创建一个云函数,在将子节点添加到父节点时触发该函数,该函数应使用添加到父节点中的子节点的参数调用url 将被调用的URL是一个托管在Google app Engine中的NodeJS Express应用程序 如果可能的话,我该怎么做呢?您可以使用node.js库来实现这一点 由于在云函数中,在执行异步任务时必须返回一个承诺,所以需要使用接口包装器进行请求,如 您可以按照以下思路做一些事情: ..... var rp = require('request-pr

我有一个firebase数据库,我希望创建一个云函数,在将子节点添加到父节点时触发该函数,该函数应使用添加到父节点中的子节点的参数调用url

将被调用的URL是一个托管在Google app Engine中的NodeJS Express应用程序

如果可能的话,我该怎么做呢?

您可以使用node.js库来实现这一点

由于在云函数中,在执行异步任务时必须返回一个承诺,所以需要使用接口包装器进行请求,如

您可以按照以下思路做一些事情:

.....
var rp = require('request-promise');
.....

exports.yourCloudFucntion = functions.database.ref('/parent/{childId}')
    .onCreate((snapshot, context) => {
      // Grab the current value of what was written to the Realtime Database.
      const createdData = snapshot.val();

      var options = {
          url: 'https://.......',
          method: 'POST',
          body: ....
          json: true // Automatically stringifies the body to JSON
      };

      return rp(options);

    });

如果要将参数传递给正在调用的HTTP(S)服务/端点,可以通过请求主体进行传递,如:

      .....
      const createdData = snapshot.val();

      var options = {
          url: 'https://.......',
          method: 'POST',
          body: {
              some: createdData.someFieldName
          },
          json: true // Automatically stringifies the body to JSON
      };
      .....
或者通过一些查询字符串键值对,例如:

      .....
      const createdData = snapshot.val();
      const queryStringObject = { 
         some: createdData.someFieldName,
         another: createdData.anotherFieldName
      };

      var options = {
          url: 'https://.......',
          method: 'POST',
          qs: queryStringObject
      };
      .....

我如何传递参数呢?与子节点名称和关联值ex类似,子节点信息类似:
2017-11-11 12:23:11
和值
123847271
这取决于您调用的服务。您应该如何传递这些参数?通过身体?作为查询字符串?