Logic Apps received the long waited response mocking a while ago (link to docs). This is a beginning (and hopefully not the end) where you can return one static response.

In most cases you would probably like to have a capability to dynamically choose which response you get from many, but at least I couldn’t use Logic App expressions to return a specific response based on received payload. The runtimeConfiguration.staticResult object’s properties don’t seem to like expressions…

Working with ARM template parameters

Anyway – a little bit of testing this feature allowed me to do something that may help in some automated or manual test scenarios with the use of ARM template parameters. So I created a parameter containing all possible results (pStaticResults) and one for which result to use (pStaticResultToUse).

    "parameters": {
        "pStaticResultToUse": {
           "type": "string",
           "metadata": {
                "description": "Name of static result to use"
            },
            "defaultValue": ""
        },
        "pStaticResults": {
           "type": "object",
           "metadata": {
                "description": "different static results"
            },
            "defaultValue": {
                "HTTP0": {
                    "outputs": {
                        "body": {
                            "code": "HTTP0"
                        },
                        "headers": {
                            "MyHeader": "MyValue0"
                        },
                        "statusCode": "OK"
                    },
                    "status": "Succeeded"
                },
                "HTTP1": {
                    "outputs": {
                        "body": {
                            "code": "HTTP1"
                        },
                        "headers": {
                            "MyHeader": "MyValue1"
                        },
                        "statusCode": "OK"
                    },
                    "status": "Succeeded"
                }
            }
        }
    }
In the deployment parameter I can now set which result is set active or should we disable the actual result – but disabling requires a bit of tweaking of the Logic App definition JSON because if you try to deploy static result with empty name, it will cause an error:
But if you set the staticResult to the template to point to a non-existing name and at the same time disable result, it will work – so some ARM template functions are needed:
Now I can change the pStaticResultToUse to the response I want deployed: HTTP0, HTTP1 or empty.
When I deploy with static response set to HTTP0 or HTTP1, workflow looks like this:
and with an empty value:
And when I run the requests to it, these are the responses for HTTP0…
and for HTTP1 it also seems to give the correct response.
With the empty one we naturally get an error as the URL pointed to unknown address:
By doing separate deployments you could automate some mock responses for different tests with this approach. Not nice, but at least a workaround until we get a real dynamic model…

Changing response manually

What I also noticed is that you can manually edit and change the response you get – but only in the code view!

If you modify the response name there, it will save and keep your all your static results.

But if you happen to save your Logic App in designer view, it will delete the other than selected response from the definition.

 

Test templates can be downloaded from here.