Using the Cloud Console

The simplest way to get started is by using the Google Cloud Console. Firstly, navigate to Navigation menu | Cloud Functions. If you haven't already, you'll need to enable the Cloud Functions API, which can be done from this page by clicking Enable API. Once enabled, click Create Function to get started.

The function creation page allows developers to specify a function name, memory allocation, the function trigger type, and code to execute. With the Source code option set to Inline editor, a simple example function will be provided in the editor pane based on the type of trigger selected. This serves as a good starting point, and we can create our first function by selecting HTTP trigger and using the following code:

exports.hello = (req, res) => {
name = req.query.name || 'unknown';
console.log('got request for ' + name);
res.send('Hello, ' + name + '!');
};

Specify hello as the Function to execute and click Create.

Once created, the console will navigate to the Cloud Functions overview page, where developers can view and interact with their functions. To test the function we just created, click on the function (function-1 by default), and navigate to the Trigger tab. Because we're using an HTTP trigger, a URL is provided to invoke this function. We can test the function by performing an HTTP GET on this URL in the Cloud Shell. Simply open the Cloud Shell and run:

curl <PROVIDED_URL>?name=user

The result should look something like this:

Hello, user!