Accessing Services Deployed as Azure Function

◷ Reading Time: 5 minutes

We learned how to deploy a service as Azure Function. Now let’s see how to access the services.

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

  • URL: <Services URL>
    e.g. https://defineagetitle-vgke35s.azurewebsites.net/api/Services/?code=TM1SdEQWa9/VtGe47ejmpahEPJmnTmv/y9b2BbCh34eM6KYXT5oLdg==
  • Request type: GET

Response

[
    {
        "packageId": "7ab01c6c04ba4f2d8bb160392cfdcdcd",
        "packageName": "defineagetitle",
        "serviceName": "person growing state",
        "serviceId": "f3d8eeb119d846cda8b28f4f238c813e",
        "packageVersion": "1",
        "serviceVersion": null,
        "packageUri": "/7ab01c6c04ba4f2d8bb160392cfdcdcd/f3d8eeb119d846cda8b28f4f238c813e/decision.function.frdp",
        "parameters": {
            "href": "/services/defineagetitle/1/person growing state"
        },
        "execute": {
            "href": "/execute/defineagetitle/1/person growing state"
        }
    },
    {
        "packageId": "7ab01c6c04ba4f2d8bb160392cfdcdcd",
        "packageName": "defineagetitle",
        "serviceName": "person growing state",
        "serviceId": "711c764034fb4e039de7c490276d66ac",
        "packageVersion": "1",
        "serviceVersion": "1",
        "packageUri": "/7ab01c6c04ba4f2d8bb160392cfdcdcd/711c764034fb4e039de7c490276d66ac/decision.function.frdp",
        "parameters": {
            "href": "/services/defineagetitle/1/person growing state/1"
        },
        "execute": {
            "href": "/execute/defineagetitle/1/person growing state/1"
        }
    }
]

Retrieve Information on Input

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

Request

  • URL: <Replace Services Uri /Services part with the service’s parameters.href value of its response>
    e.g. https://defineagetitle-vgke35s.azurewebsites.net/api/services/defineagetitle/1/person growing state/1/?code=TM1SdEQWa9/VtGe47ejmpahEPJmnTmv/y9b2BbCh34eM6KYXT5oLdg==
  • Request type: GET
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": "Importal"
                        }
                    ]
                }
            ],
            "Namespace": "Samples"
        }
    }
]

Execute the Service

Using the Execute Url, we can execute the service and retrieve output from our function app deployed in Azure.

Request

  • URL: <Execute Url>
    e.g. https://defineagetitle-vgke35s.azurewebsites.net/api/Execute/defineagetitle/1/person growing state/1?code=YF/cCCUW/C6nIcqjszaTCYlIM8V5c4Kmr86t4PoFeyeZPNJTNIaRVQ==
  • Request type: POST
  • Body: <input of your service>

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 Azure, and provide the results accordingly. In this example, since we entered 50 as age, it returned ‘Adult’ as the title. In the decision table, you can see that we have defined the age group 19-99 as ‘Adult’.

{
    "isCanceled": false,
    "invocationId": "ec927277-68d3-4e54-a202-d983671a5f48",
    "elapsed": "00:00:00.0115451",
    "outputs": [
        {
            "name": "person",
            "value": "{\"Age\":50,\"Title\":\"Adult\"}"
        }
    ]
}
Updated on March 29, 2021

Was this article helpful?

Related Articles