'return-response' Policy Statement


How to use the "return-response" Policy statement to build the response from scratch for an Azure API service operation?

✍: FYIcenter.com


The "return-response" Policy Statement allows you to stop the Azure API processing immediately and return with the given response.

The "forward-request" statement can be used in three ways:

1. Return an empty response with status of 200:


2. Return a new response constructed with "set-status", "set-headers" and "set-body" child policy statements:

  <set-status... />  
  <set-header ... />  
  <set-body .../>  

For example, the following "inbound" policy returns a new response with status of 401:

      <set-status code="401" reason="Unauthorized"/>  
      <set-header name="WWW-Authenticate" exists-action="override">  
         <value>Bearer error="invalid_token"</value>  

3. Return an existing response created previously:

<return-response response-variable-name="existing context variable">

For example, the following "inbound" policy returns an existing response stored in a context variable:

<return-response response-variable-name="context.Variables["loginResponse"]">


Policy to Control Backend Service

⇒⇒Microsoft Azure API Management Tutorials

2018-01-13, 204👍, 0💬