Complete the code to create an HTTP trigger function named 'helloWorld'.
exports.helloWorld = functions.https.[1]((req, res) => { res.send('Hello from Firebase!'); });
The correct method to create an HTTP trigger function in Firebase is onRequest. It listens for HTTP requests.
Complete the code to send a JSON response with a message in the HTTP function.
exports.sendJson = functions.https.onRequest((req, res) => {
res.[1]({ message: 'Hello JSON!' });
});Use res.json() to send a JSON response in an HTTP function.
Fix the error in the HTTP function to correctly access query parameters.
exports.queryParam = functions.https.onRequest((req, res) => {
const name = req.[1].name;
res.send(`Hello, ${name}!`);
});Query parameters in HTTP requests are accessed via req.query.
Fill both blanks to create an HTTP function that responds with status 200 and a JSON message.
exports.statusJson = functions.https.onRequest((req, res) => {
res.status([1]).[2]({ message: 'Success' });
});Use res.status(200) to set HTTP status OK, then res.json() to send JSON.
Fill all three blanks to create an HTTP function that reads a POST JSON body field 'name' and responds with a greeting.
exports.greetPost = functions.https.onRequest((req, res) => {
const name = req.[1].[2];
res.[3]({ greeting: `Hello, ${name}!` });
});POST JSON data is accessed via req.body. The field is name. Use res.json() to send JSON response.