HTTP trigger Cloud Function in Flutter web
Question:
I am trying to call a HTTP trigger Cloud Function
from Flutter
. I keep getting errors in the console while passing the parameters to the function.
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'hello_world',
);
final HttpsCallableResult result = await callable.call(
<String, dynamic>{
'message': 'hello world!',
},
);
Can someone point out what is it that I am doing wrong. The Cloud function
used is
def hello_world(request):
request_json = request.get_json()
if request.args and 'message' in request.args:
return request.args.get('message')
elif request_json and 'message' in request_json:
return request_json['message']
else:
return f'Hello World!'
Answers:
I see from your screenshot of the Google Cloud Console that your HTTP Cloud Function is written in Python.
On the other hand, in your Dart code, you are calling a Callable Cloud Function.
At the time of writing, Callable Cloud Functions are only supported on Cloud Functions by using the Firebase SDK for Node.js.
If you want an HTTP Cloud Function written in Python to work with your Dart code you will need to implement the protocol for https.onCall
in the Cloud Function itself.
You’ll find an example here (untested).
Update following your comment above: From you Cloud Function code, we can confirm that you don’t implement the protocol for https.onCall
.
I am trying to call a HTTP trigger Cloud Function
from Flutter
. I keep getting errors in the console while passing the parameters to the function.
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'hello_world',
);
final HttpsCallableResult result = await callable.call(
<String, dynamic>{
'message': 'hello world!',
},
);
Can someone point out what is it that I am doing wrong. The Cloud function
used is
def hello_world(request):
request_json = request.get_json()
if request.args and 'message' in request.args:
return request.args.get('message')
elif request_json and 'message' in request_json:
return request_json['message']
else:
return f'Hello World!'
I see from your screenshot of the Google Cloud Console that your HTTP Cloud Function is written in Python.
On the other hand, in your Dart code, you are calling a Callable Cloud Function.
At the time of writing, Callable Cloud Functions are only supported on Cloud Functions by using the Firebase SDK for Node.js.
If you want an HTTP Cloud Function written in Python to work with your Dart code you will need to implement the protocol for https.onCall
in the Cloud Function itself.
You’ll find an example here (untested).
Update following your comment above: From you Cloud Function code, we can confirm that you don’t implement the protocol for https.onCall
.