Node.js
post
GoogleCloudFunctions

Google Cloud Functions で Post の引数を受け取る

引数のない場合の使い方はこちらです。
Google Cloud Functions の使い方

index.js
/**
 * HTTP Cloud Function.
 *
 * @param {Object} req Cloud Function request context.
 * @param {Object} res Cloud Function response context.
 */
exports.gcf_post = (req, res) => {
  var str_out = ""
  str_out += "これはテストです。\n"
  str_out += "Good Evening\n"
  str_out += "今晩は\n"
  str_out += "Mar/11/2018 PM 18:02\n"
  const user = req.body['user']
  const password = req.body['password']
  str_out += "user = " + user + "\n"
  str_out += "password = " + password + "\n"
  res.send(str_out)
}

デプロイ

gcloud beta functions deploy gcf_post --source . --trigger-http

Curl でテスト

curl_post.sh
HOST="https://us-central1-my-project-aug-29-2016.cloudfunctions.net"
curl $HOST/gcf_post -d 'user=jiro&password=123456'

実行結果

$ ./curl_post.sh 
これはテストです。
Good Evening
今晩は
Mar/11/2018 PM 18:02
user = jiro
password = 123456

Get の引数の受け取り方はこちら
Google Cloud Functions で Get の引数を受け取る