0
0
Firebasecloud~10 mins

Resource and request objects in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access the resource object in a Firebase Cloud Function.

Firebase
exports.myFunction = functions.https.onRequest(([1], response) => {
  response.send('Hello World');
});
Drag options to blanks, or click blank then click option'
Arequest
Bresource
Cevent
Dreq
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'resource' instead of 'req' as the first parameter.
Naming the first parameter 'response' instead of 'req'.
2fill in blank
medium

Complete the code to send a JSON response using the response object.

Firebase
exports.myFunction = functions.https.onRequest((req, [1]) => {
  [1].json({ message: 'Success' });
});
Drag options to blanks, or click blank then click option'
Arequest
Bresponse
Cres
Devent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'request' instead of 'response' as the second parameter.
Using 'response' but calling the variable 'req'.
3fill in blank
hard

Fix the error in accessing a property from the request object.

Firebase
exports.myFunction = functions.https.onRequest((req, res) => {
  const userId = req.[1].userId;
  res.send(`User ID is ${userId}`);
});
Drag options to blanks, or click blank then click option'
Abody
Bparams
Cquery
Dresource
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'params' when the data is in the request body.
Using 'query' for POST request data.
4fill in blank
hard

Fill both blanks to extract a path parameter and send it in the response.

Firebase
exports.myFunction = functions.https.onRequest((req, res) => {
  const itemId = req.[1].itemId;
  res.[2](`Item ID: ${itemId}`);
});
Drag options to blanks, or click blank then click option'
Aparams
Bsend
Cbody
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'body' to get path parameters.
Using 'json' instead of 'send' for plain text.
5fill in blank
hard

Fill all three blanks to correctly read a query parameter, check its value, and respond accordingly.

Firebase
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');
  }
});
Drag options to blanks, or click blank then click option'
Aquery
Bstart
Cjson
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'body' instead of 'query' for URL parameters.
Sending plain text instead of JSON response.