Complete the code to access the resource object in a Firebase Cloud Function.
exports.myFunction = functions.https.onRequest(([1], response) => { response.send('Hello World'); });
The first parameter in an HTTPS Cloud Function is the request object, commonly named req.
Complete the code to send a JSON response using the response object.
exports.myFunction = functions.https.onRequest((req, [1]) => { [1].json({ message: 'Success' }); });
The second parameter is the response object, commonly named res, used to send data back.
Fix the error in accessing a property from the request object.
exports.myFunction = functions.https.onRequest((req, res) => {
const userId = req.[1].userId;
res.send(`User ID is ${userId}`);
});The body property contains data sent in the request payload, including userId.
Fill both blanks to extract a path parameter and send it in the response.
exports.myFunction = functions.https.onRequest((req, res) => {
const itemId = req.[1].itemId;
res.[2](`Item ID: ${itemId}`);
});Path parameters are accessed via req.params. The response is sent using res.send().
Fill all three blanks to correctly read a query parameter, check its value, and respond accordingly.
exports.myFunction = functions.https.onRequest((req, res) => {
const action = req.[1].action;
if (action === '[2]') {
res.[3]({ result: 'Action received' });
} else {
res.status(400).send('Invalid action');
}
});Query parameters are accessed via req.query. We check if action equals 'start' and respond with JSON using res.json().