I\'ve just finished writing a Google Cloud Function in the Beta Python 3.7 runtime with an HTTP trigger. Now I\'m trying to figure out how to pass a string variable to my f
You'd pass variables to the function the same way you'd pass variables to any URL:
GET
with query parameters:def test(request):
name = request.args.get('name')
return f"Hello {name}"
$ curl -X GET https://us-central1-<PROJECT>.cloudfunctions.net/test?name=World
Hello World
POST
with a form:def test(request):
name = request.form.get('name')
return f"Hello {name}"
$ curl -X POST https://us-central1-<PROJECT>.cloudfunctions.net/test -d "name=World"
Hello World
POST
with JSON:def test(request):
name = request.get_json().get('name')
return f"Hello {name}"
$ curl -X POST https://us-central1-<PROJECT>.cloudfunctions.net/test -d '{"name":"World"}'
Hello World
More details can be found here: https://cloud.google.com/functions/docs/writing/http