Last active
          April 4, 2024 13:44 
        
      - 
      
- 
        Save shapi78/33b2e1489a46a640ca1bef2deb462ac7 to your computer and use it in GitHub Desktop. 
Revisions
- 
        shapi78 revised this gist Apr 4, 2024 . 2 changed files with 44 additions and 2 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ Create a cloud function: Go to Cloud Functions by searching for “Cloud Functions” in search bar: * Press “create function” button and fill up the form: Environment: 2nd gen Function name: <pick name> Region: <choose region> Choose “Allow unauthorized invocations” Press “Next” and lets write the code for the function. Lets pick the code language that we use: Next, write you code and correct the entry point. The code i used is taking 2 numbers and sum them up: ```import functions_framework @functions_framework.http def calculate(request): """HTTP Cloud Function to perform calculation on two numbers. Args: request (flask.Request): The request object. Returns: The result of the calculation as JSON. """ request_json = request.get_json(silent=True) if request_json and 'num1' in request_json and 'num2' in request_json: num1 = request_json['num1'] num2 = request_json['num2'] else: return {'error': 'Please provide num1 and num2 in the request body as JSON.'}, 400 try: result = float(num1) + float(num2) return {'result': result}, 200 except ValueError: return {'error': 'Invalid input. Please provide valid numbers.'}, 400 ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ 
- 
        shapi78 created this gist Apr 4, 2024 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ Create a cloud function: Go to Cloud Functions by searching for “Cloud Functions” in search bar: