azure-api-management

Applying outbound policies to a mocked operation in Azure API Management


I have an Azure API Management API for which I am mocking a particular operation. I have set up the mock to simulate the back-end service response (including urls in the response that look like they are emerging from the back-end service).

I have found that none of my outbound policies, including the redirect-content-urls policy, are getting applied for this mocked response so the urls being returned to the consumer are incorrect.

Now I know I can work around this in the mock itself, but what I would like is to be able to have all of my outbound policies applied to the mock response so that I can fully test my API without needing the back-end in place.

Is there a way around this other than by stubbing the back-end service?


Solution

  • The mock response policy will pick up the matching response from the responses that are configured for the api. If no response is defined then an empty response will be returned for the status code. As for the execution, as soon as the policy is encountered the policy execution is interrupted and the service will return the response based on your mock policy. Consider following scenarios where the mock-response policy is placed and its effect

    1. Inbound: In this as soon as the mock response policy is encountered, execution is halted and the response is returned. You can't really apply the content-redirect-url property here. It will throw an exception in execution of the policy engine
    2. Outbound: For the mock response to work in this section, you will have to have a backend service where you will send the request (which is not possible as there is no backend!) after which the outbound policies will be applied.

    So there is no direct way to implement the outbound polices when the mock response is defined in inbound. Best bet is to implemented the masked redirect content url in the mock response sample itself.