11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

Last updated at Posted at 2018-03-11

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

フォルダー構造

$ tree 
.
├── index.js
└── package.json
index.js
/**
 * HTTP Cloud Function.
 *
 * @param {Object} req Cloud Function request context.
 * @param {Object} res Cloud Function response context.
 */
exports.good_evening = (req, res) => {
  var str_out = ""
  str_out += "これはテストです。\n"
  str_out += "Good Evening\n"
  str_out += "今晩は\n"
  str_out += "Mar/11/2018 PM 17:35\n"
  const user = req.query['user']
  const password = req.query['password']
  str_out += "user = " + user + "\n"
  str_out += "password = " + password + "\n"
  res.send(str_out)
}
package.json
{
  "name": "sample-http",
  "version": "0.0.1"
}

デプロイ

gcloud functions deploy function-apr06 \
--entry-point=good_evening \
--trigger-http \
--runtime=nodejs16 \
--region asia-northeast1

Curl でテスト

curl_get.sh
HOST="https://asia-northeast1-project-apr06.cloudfunctions.net/function-apr06"
curl $HOST/good_evening?user="jiro"\&password="123456" \
        -H "Authorization: bearer $(gcloud auth print-identity-token)"

実行結果

$ ./curl_get.sh 
これはテストです。
Good Evening
今晩は
Mar/11/2018 PM 17:35
user = jiro
password = 123456
11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?