Accessing Services Deployed as Google Cloud Function

◷ Reading Time: 5 minutes

Get Service Details Using Services URL

To demonstrate how to retrieve service information, we will be using Postman, but you can use any API testing tool for this.

Retrieve All the Available Services

You can use the Services URL to get the list of available services along with their details. For example, if your package has three services, you can retrieve the service details of all three services.

Request

Response

[
    {
        "packageId": "8ad25252fc2f43e99b7d7224d1a510e9",
        "packageName": "age-service",
        "serviceName": "person growing state",
        "serviceId": "7e130b07b8964ea5b796d3383ac91027",
        "packageVersion": "1",
        "serviceVersion": "1",
        "packageUri": "/8ad25252fc2f43e99b7d7224d1a510e9/7e130b07b8964ea5b796d3383ac91027/decision.function.frdp",
        "parameters": {
            "href": "/services/age-service/1/person growing state/1"
        },
        "execute": {
            "href": "/execute/age-service/1/person growing state/1"
        }
    },
    {
        "packageId": "8ad25252fc2f43e99b7d7224d1a510e9",
        "packageName": "age-service",
        "serviceName": "person growing state",
        "serviceId": "a21be108580c49d88a3b2857835d7878",
        "packageVersion": "1",
        "serviceVersion": null,
        "packageUri": "/8ad25252fc2f43e99b7d7224d1a510e9/a21be108580c49d88a3b2857835d7878/decision.function.frdp",
        "parameters": {
            "href": "/services/age-service/1/person growing state"
        },
        "execute": {
            "href": "/execute/age-service/1/person growing state"
        }
    }
]

Retrieve Information on Input

You can retrieve further information on the input data structure, entry URI, and concept.

Service’s parameters.href value retrieved from the Services Uri

Response

In this response, we can see that the

[
    {
        "name": "person",
        "direction": "InOut",
        "assembly": "PersonConcept.xml",
        "type": "Person",
        "concept": {
            "filename": "PersonConcept.xml",
            "types": [
                {
                    "name": "Person",
                    "type": "Fact",
                    "members": [
                        {
                            "name": "Age",
                            "type": "int"
                        },
                        {
                            "name": "Title",
                            "fact": "Title"
                        }
                    ]
                },
                {
                    "name": "Title",
                    "type": "Option",
                    "members": [
                        {
                            "name": "Infant"
                        },
                        {
                            "name": "Kid"
                        },
                        {
                            "name": "Teen"
                        },
                        {
                            "name": "Young"
                        },
                        {
                            "name": "Adult"
                        },
                        {
                            "name": "Immortal"
                        }
                    ]
                }
            ],
            "namespace": "Samples"
        }
    }
]

You may also opt to retrieve the swagger specification by using the swagger endpoint.

Execute the Service

Using the Execute Url, we can execute the service and retrieve output from our AWS Lambda deployed in AWS.

Request

For the request body, the original input should be re-formatted as below, surrounded by an inputs tag. If you use the original input instead, it will give an error with the message, “Incorrect number of parameters specified.”


  "inputs": [
            {
              "name": "person",
              "value": {
                "Age":50,
                "Title": null
              }
            }
        ]
}


The original input
{
     "person":
     {
         "Age":50,
         "Title":null
     }
 }

Response

It will run the app deployed in Google Cloud, and provide the results accordingly. In this example, since we entered 50 as age, it returned ‘Kid’ as the title. In the decision table, you can see that we have defined the age group 39-99 as ‘Kid’.

{
    "isCanceled": false,
    "invocationId": "arn:aws:lambda:us-west-2:627175391071:function:age-service-132633758128829094",
    "elapsed": "00:00:00.0014247",
    "outputs": [
        {
            "name": "person",
            "value": "{\"Age\":50,\"Title\":\"Kid\"}"
        }
    ]
}

Checking your Function in Google Cloud Console

On your Google Cloud Console page, you will see all the functions created by FlexRule through Google Cloud Function deploy.

The Function Name is required when updating an existing function.

The code as seen in the Execute and Service URLs are to be found in Cloud Function page of the Google Cloud Console.

Updated on June 3, 2021

Was this article helpful?

Related Articles