0
0
Firebasecloud~10 mins

HTTP trigger functions 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 create an HTTP trigger function named 'helloWorld'.

Firebase
exports.helloWorld = functions.https.[1]((req, res) => {
  res.send('Hello from Firebase!');
});
Drag options to blanks, or click blank then click option'
AonRequest
BonCall
ConEvent
DonTrigger
Attempts:
3 left
💡 Hint
Common Mistakes
Using onCall instead of onRequest for HTTP triggers.
Using onEvent which is not a valid method here.
2fill in blank
medium

Complete the code to send a JSON response with a message in the HTTP function.

Firebase
exports.sendJson = functions.https.onRequest((req, res) => {
  res.[1]({ message: 'Hello JSON!' });
});
Drag options to blanks, or click blank then click option'
Ajson
BsendStatus
CsendFile
DsendText
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendText which is not a valid method.
Using sendFile which is for sending files.
3fill in blank
hard

Fix the error in the HTTP function to correctly access query parameters.

Firebase
exports.queryParam = functions.https.onRequest((req, res) => {
  const name = req.[1].name;
  res.send(`Hello, ${name}!`);
});
Drag options to blanks, or click blank then click option'
Abody
Bparams
Cheaders
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Using req.body which is for POST data.
Using req.params which is for URL path parameters.
4fill in blank
hard

Fill both blanks to create an HTTP function that responds with status 200 and a JSON message.

Firebase
exports.statusJson = functions.https.onRequest((req, res) => {
  res.status([1]).[2]({ message: 'Success' });
});
Drag options to blanks, or click blank then click option'
A200
Bjson
Csend
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using status 404 which means not found.
Using send instead of json for JSON responses.
5fill in blank
hard

Fill all three blanks to create an HTTP function that reads a POST JSON body field 'name' and responds with a greeting.

Firebase
exports.greetPost = functions.https.onRequest((req, res) => {
  const name = req.[1].[2];
  res.[3]({ greeting: `Hello, ${name}!` });
});
Drag options to blanks, or click blank then click option'
Abody
Bname
Cjson
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to get POST data from req.query.
Using res.send instead of res.json for JSON response.