引数のない場合の使い方はこちらです。
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 functions deploy gcf_post --source . --trigger-http \
--runtime=nodejs16 \
--region asia-northeast1
Curl でテスト
curl_post.sh
HOST="https://asia-northeast1-my-project-aug-29-2016.cloudfunctions.net"
curl $HOST/gcf_post \
-H "Authorization: bearer $(gcloud auth print-identity-token)" \
-d 'user=jiro&password=123456'
実行結果
$ ./curl_post.sh
これはテストです。
Good Evening
今晩は
Mar/11/2018 PM 18:02
user = jiro
password = 123456
Httpie でテスト
httpie_post.sh
HOST="https://asia-northeast1-my-project-aug-29-2016.cloudfunctions.net"
http $HOST"/gcf_post" \
"Authorization: bearer $(gcloud auth print-identity-token)" \
user=jiro password=123456
Get の引数の受け取り方はこちら
Google Cloud Functions で Get の引数を受け取る