HTTP Hello World - Get
Stay organized with collections
Save and categorize content based on your preferences.
Function that prints "Hello world!" in response to a GET request.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis webpage showcases code samples for creating a simple "Hello World!" function that responds to GET requests in various languages.\u003c/p\u003e\n"],["\u003cp\u003eThe provided examples demonstrate how to implement this function in C#, Go, Java, Kotlin, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample includes instructions to set up Application Default Credentials for authenticating to Cloud Run functions.\u003c/p\u003e\n"],["\u003cp\u003eFurther resources are linked for users to explore detailed documentation, related language concepts, and deployment guides for creating functions.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud sample browser is linked for searching and filtering other code samples.\u003c/p\u003e\n"]]],[],null,["# HTTP Hello World - Get\n\nFunction that prints \"Hello world!\" in response to a GET request.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Create and deploy an HTTP Cloud Run function by using Java (1st gen)](/functions/1stgendocs/create-deploy-http-java-1st-gen)\n- [HTTP Tutorial](/functions/1stgendocs/tutorials/http-1st-gen)\n- [JVM Languages](/functions/1stgendocs/concepts/jvm-langs)\n- [Quickstart: Deploy a Cloud Run function\n using the gcloud CLI](/run/docs/quickstarts/functions/deploy-functions-gcloud)\n\nCode sample\n-----------\n\n### C#\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n using Google.Cloud.Functions.Framework;\n using Microsoft.AspNetCore.Http;\n using System.Threading.Tasks;\n\n namespace HelloWorld;\n\n public class Function : IHttpFunction\n {\n public async Task HandleAsync(HttpContext context)\n {\n await context.Response.WriteAsync(\"Hello World!\", context.RequestAborted);\n }\n }\n\n### Go\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n // Package helloworld provides a set of Cloud Functions samples.\n package helloworld\n\n import (\n \t\"fmt\"\n \t\"net/http\"\n\n \t\"github.com/GoogleCloudPlatform/functions-framework-go/functions\"\n )\n\n func init() {\n \tfunctions.HTTP(\"HelloGet\", helloGet)\n }\n\n // helloGet is an HTTP Cloud Function.\n func helloGet(w http.ResponseWriter, r *http.Request) {\n \tfmt.Fprint(w, \"Hello, World!\")\n }\n\n### Java\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n package functions;\n\n import com.google.cloud.functions.HttpFunction;\n import com.google.cloud.functions.HttpRequest;\n import com.google.cloud.functions.HttpResponse;\n import java.io.BufferedWriter;\n import java.io.IOException;\n\n public class HelloWorld implements HttpFunction {\n // Simple function to return \"Hello World\"\n @Override\n public void service(HttpRequest request, HttpResponse response)\n throws IOException {\n BufferedWriter writer = response.getWriter();\n writer.write(\"Hello World!\");\n }\n }\n\n### Kotlin\n\n import com.google.cloud.functions.HttpFunction\n import com.google.cloud.functions.HttpRequest\n import com.google.cloud.functions.HttpResponse\n import java.io.IOException\n import java.util.logging.Logger\n\n class HelloWorld : HttpFunction {\n // Simple function to return \"Hello World\"\n @Throws(IOException::class)\n override fun service(request: HttpRequest, response: HttpResponse) {\n response.writer.write(\"Hello World!\")\n }\n }\n\n### Node.js\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const functions = require('@google-cloud/functions-framework');\n\n // Register an HTTP function with the Functions Framework that will be executed\n // when you make an HTTP request to the deployed function's endpoint.\n functions.http('helloGET', (req, res) =\u003e {\n res.send('Hello World!');\n });\n\n### PHP\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n use Psr\\Http\\Message\\ServerRequestInterface;\n\n function helloGet(ServerRequestInterface $request): string\n {\n return 'Hello, World!' . PHP_EOL;\n }\n\n### Python\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import functions_framework\n\n @functions_framework.http\n def hello_get(request):\n \"\"\"HTTP Cloud Function.\n Args:\n request (flask.Request): The request object.\n \u003chttps://flask.palletsprojects.com/en/1.1.x/api/#incoming-request-data\u003e\n Returns:\n The response text, or any set of values that can be turned into a\n Response object using `make_response`\n \u003chttps://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response\u003e.\n Note:\n For more information on how Flask integrates with Cloud\n Functions, see the `Writing HTTP functions` page.\n \u003chttps://cloud.google.com/functions/docs/writing/http#http_frameworks\u003e\n \"\"\"\n return \"Hello World!\"\n\n### Ruby\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n require \"functions_framework\"\n\n FunctionsFramework.http \"hello_get\" do |_request|\n # The request parameter is a Rack::Request object.\n # See https://www.rubydoc.info/gems/rack/Rack/Request\n\n # Return the response body as a string.\n # You can also return a Rack::Response object, a Rack response array, or\n # a hash which will be JSON-encoded into a response.\n \"Hello World!\"\n end\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=functions)."]]