0
0
Firebasecloud~20 mins

HTTP trigger functions in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase HTTP Trigger Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Firebase HTTP trigger function?

Consider this Firebase HTTP trigger function code snippet:

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send('Hello from Firebase!');
});

What will the client receive when making a GET request to this function?

Firebase
exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send('Hello from Firebase!');
});
AThe client receives an error because the function does not return a promise.
BThe client receives a JSON object {message: 'Hello from Firebase!'} as the response body.
CThe client receives an empty response with status 200.
DThe client receives the string 'Hello from Firebase!' as the response body.
Attempts:
2 left
💡 Hint

Look at what the response.send() method sends back.

📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this Firebase HTTP trigger function

Which option contains the correct syntax for defining a Firebase HTTP trigger function?

Firebase
exports.myFunction = functions.https.onRequest((req, res) => {
  res.send('Hi');
});
A
exports.myFunction = functions.https.onRequest((req, res) => {
  res.send('Hi')
});
B
exports.myFunction = functions.https.onRequest((req, res) => {
  res.send('Hi');
});
C
exports.myFunction = functions.https.onRequest(req, res) => {
  res.send('Hi');
};
D
exports.myFunction = functions.https.onRequest = (req, res) => {
  res.send('Hi');
};
Attempts:
2 left
💡 Hint

Check the arrow function syntax and parentheses.

optimization
advanced
2:00remaining
Which option optimizes response time for a Firebase HTTP trigger function?

You want your Firebase HTTP trigger function to respond quickly without waiting for asynchronous tasks. Which option achieves this?

Firebase
exports.fastResponse = functions.https.onRequest(async (req, res) => {
  // Some async task
  await someAsyncTask();
  res.send('Done');
});
ARemove <code>await</code> and call <code>someAsyncTask()</code> without waiting, then send response immediately.
BUse <code>setTimeout</code> to delay the response by 2 seconds.
CKeep <code>await</code> so the function waits for the async task before responding.
DReturn a promise that never resolves to keep the function alive.
Attempts:
2 left
💡 Hint

Think about sending the response without waiting for the async task.

🧠 Conceptual
advanced
2:00remaining
What happens if a Firebase HTTP trigger function does not send a response?

If a Firebase HTTP trigger function does not call response.send() or similar methods, what will happen?

AThe function logs an error but sends a 200 OK response.
BFirebase automatically sends a default success response.
CThe client request will hang until timeout because no response is sent.
DThe function throws a syntax error immediately.
Attempts:
2 left
💡 Hint

Think about what happens when a server never replies to a request.

🔧 Debug
expert
2:00remaining
Why does this Firebase HTTP trigger function cause a timeout error?

Examine this function:

exports.timeoutFunc = functions.https.onRequest((req, res) => {
  someAsyncOperation();
  // Missing response.send or end
});

Why does this cause a timeout error?

ABecause the function never sends a response, the client waits indefinitely until timeout.
BBecause <code>someAsyncOperation()</code> is not awaited, it causes a syntax error.
CBecause <code>response.send()</code> is called twice causing a conflict.
DBecause the function returns a promise that rejects immediately.
Attempts:
2 left
💡 Hint

Check if the function sends any response back to the client.