Prompt

How do I deploy an HTTP API with Google Cloud Functions?

Technology / Cloud Infrastructure1 observationLast seen Oct 25, 2026

Latest observation

Oct 25, 2026OpenAI APIWeb search: off

To deploy an HTTP API with Google Cloud Functions, you typically create a function that handles HTTP requests and then deploy it as an HTTP-triggered function.

1) Prerequisites

  • A Google Cloud project
  • Billing enabled
  • gcloud CLI installed and authenticated
gcloud auth login
gcloud config set project PROJECT_ID

Also enable the Cloud Functions API if needed:

gcloud services enable cloudfunctions.googleapis.com

2) Write your function

Node.js example

Create index.js:

exports.api = (req, res) => {
  if (req.method === 'GET') {
    res.status(200).json({ message: 'Hello from Cloud Functions!' });
  } else {
    res.status(405).send('Method Not Allowed');
  }
};

Create package.json:

{
  "name": "http-api",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {}
}

3) Deploy the function

Deploy as an HTTP function and allow unauthenticated access if you want public API access:

gcloud functions deploy api \
  --runtime nodejs20 \
  --trigger-http \
  --allow-unauthenticated \
  --entry-point api

After deployment, gcloud will output a URL for your API.


4) Test it

curl https://REGION-PROJECT_ID.cloudfunctions.net/api

You should get:

{"message":"Hello from Cloud Functions!"}

5) Add routes/logic for a real API

Cloud Functions is a single handler, so you usually implement routing inside the function:

exports.api = (req, res) => {
  const { method, path } = req;

  if (method === 'GET' && path === '/users') {
    res.json([{ id: 1, name: 'Alice' }]);
  } else if (method === 'POST' && path === '/users') {
    res.status(201).json({ status: 'created' });
  } else {
    res.status(404).send('Not found');
  }
};

6) Optional: Use Cloud Functions with API Gateway

If you need:

  • API keys
  • Auth policies
  • Rate limiting
  • Better API management

put API Gateway in front of Cloud Functions.


Notes

  • Cloud Functions is best for lightweight APIs and event-driven workloads.
  • For more complex HTTP APIs, consider Cloud Run or API Gateway + Cloud Run.
  • In newer Google Cloud setups, Cloud Functions (2nd gen) is often preferred.

If you want, I can also show you:

  1. a Python version,
  2. a 2nd gen deployment, or
  3. how to expose multiple routes in one function.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.