Search code examples
node.jsfirebasegoogle-cloud-functionsfirebase-cli

How can I get the params from a "get request" in a firebase function?


I know the request param in a firebase https.onRequest corresponds to a Express response.

I want to run the cloud function using this format (local testing):

http://localhost:5000/test-2c6e8/us-central1/coins?userid=1

So, now from the cloud function I just want to get the userId param. The test function I have written is:

exports.coins = functions.https.onRequest((request, response) => 
{
    var db = admin.firestore();
    response.json({query: JSON.stringify(request.query),
                   params: JSON.stringify(request.params),
                   body: JSON.stringify(request.body)});
    response.end();
});

and this is the output I get:

query   "{}"
params  "{\"0\":\"\"}"
body    "{}"

I have tried multiple things without any luck. Why is this happening?


Solution

  • Short answer is req.query.name_of_the_parameter; for the long answer, you can read here.