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
.
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.