Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Firebase HTTP Cloud functions locally using a query string with GET

I have a HTTP Cloud function on Firebase. I can successfully invoke the functions following this tutorial with GET methods without query strings.

> test.get() 

My question is how do I test HTTP function with query strings? How do I pass it to the invocation call?

I tried this on the shell

> test.get({"name":"test"})

and on my index.js I tried to print the name:

exports.test= functions.https.onRequest((req, res) => {
    console.log(req.query.name);
});

It did not work and returned undefined.

like image 276
ellaRT Avatar asked Dec 14 '25 02:12

ellaRT


1 Answers

The documentation you cited says this:

For invoking HTTPS functions in the shell, usage is the same as the request NPM module, but replace request with the name of the function you want to emulate.

Notice the link to the documentation for the request module. You will have to use its APIs for making the test request. On that linked page, the more specific documentation you're looking for is here:

https://www.npmjs.com/package/request#requestoptions-callback

What you want to pay attention to is the properties for the first argument called "options". This object has a lot of potential properties that affect the request. To send a query string, you should use the qs property, like this:

test.get({ qs:{ name:"foo" } })

This will set the name query string parameter to foo for the test invocation.

like image 64
Doug Stevenson Avatar answered Dec 16 '25 22:12

Doug Stevenson



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!