Courseiva
Deploying and Implementing a Cloud SolutionmediumMultiple ChoiceObjective-mapped

Google ACE Deploying and Implementing a Cloud Solution Practice Question

A developer is using Cloud Functions with HTTP trigger. The function needs to process a request payload and return a response. What is the correct way to send a JSON response from the function?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

res.send({ 'status': 'ok' })

In Cloud Functions (Node.js runtime), the response is sent via the res (response) object. The correct method is res.send() or res.json(). res.send() can send JSON directly.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • response.end(JSON.stringify({ 'status': 'ok' }))

    Why it's wrong here

    The parameter is named 'res' in Cloud Functions' HTTP trigger signature, so 'response' is undefined in this scope. Even if it were defined, calling .end() only writes the raw string without setting the Content-Type header to application/json; the client would receive the correct body but not as encoded JSON. In practice, this code would raise a ReferenceError before sending anything, which is why it is incorrect.

  • return { 'status': 'ok' }

    Why it's wrong here

    For an HTTP-triggered Cloud Function, returning a plain object from your function does not automatically send it to the client. The function signature provides a response object, and you must explicitly call a method like res.send() or res.json() to write the HTTP response. The returned value is ignored unless it is a Promise that triggers asynchronous work; otherwise, the function ends without completing the request, causing a timeout or a 500 error.

  • context.done(null, { 'status': 'ok' })

    Why it's wrong here

    The context.done callback is part of the background (event-driven) functions contract, not HTTP triggers. When using an HTTP trigger, the function receives a request and a response object, and you must use res.send(), res.end(), or res.status() to finish the request. If you attempt to call context.done, the context object may be undefined for an HTTP function, and even if it exists, it cannot send a response to the client, so the request remains unresolved.

  • res.send({ 'status': 'ok' })

    Why this is correct

    res.send({ 'status': 'ok' }) is the correct, recommended way to complete an HTTP-triggered Cloud Function. When passed an object, res.send automatically serializes it to JSON and sets the Content-Type response header to application/json, and it terminates the request. This works because Cloud Functions' HTTP handlers receive an Express-style response object, making this pattern highly reliable and idiomatic.

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

About these practice questions

One of 769 original ACE practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This ACE practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the ACE exam.