Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data to Google Cloud Function using Postman

very new to server side programming, so my apologies in advance

I created a google cloud function that calls an API (i figured that part out it works ), the cloud function is invoked via http. for my environment am using Node Js and am using axios to make api call from within my gcloud function

now am stuck on 1) how do I send the data to the gcloud function (I am assuming a POST, and am also assuming it is sent in the body?) at the moment am using Postman to call the gcloud function. I have been experimenting with variations but I get nothing but Internal Server Errors.

2) How to use the parameters I sent to the google cloud function.

am assuming something like below? but am really not sure

exports.helloWorld = async(x,y,req, res) => {

thanks in advance

like image 317
slair Avatar asked Oct 15 '25 16:10

slair


1 Answers

Yes, you are correct, POST is one of the most used methods to send data via your calls. You need to look out into some specific topics, such as for the type of data that you will be sending and how it's going to be handled and with CORS (Cross-origin resource sharing ) as well, since it be will crossing origins and this usually causes errors.

Including that, you are almost correct on how to use the parameters. It will look more like this below - this code and other examples are available in the official documentation.

exports.helloWorld = functions.https.onRequest((req, res) => {
  // ...
});

You can continue to use Postman to call the functions, but you can use a cURL as well, to do that. The cURL will be something like this:

curl -X POST "https://YOUR_REGION-YOUR_PROJECT_ID.cloudfunctions.net/FUNCTION_NAME" -H "Content-Type:application/json" --data '{"name":"Keyboard Cat"}'

I would recommend you to take a look at the official documentation Call functions via HTTP requests to get a better understanding of how it works. Besides that, this other post from the Community here, should provide you with a complete example of Cloud Functions with HTTP and Node.js.

Let me know if the information helped you!

like image 182
gso_gabriel Avatar answered Oct 18 '25 12:10

gso_gabriel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!