【问题标题】:Azure API Management. How to add URL path filteringAzure API 管理。如何添加 URL 路径过滤
【发布时间】:2021-07-30 05:27:39
【问题描述】:

我正在 Azure 中使用 API 管理构建 API。现在我不确定如何配置策略,因此我可以使用 URL 过滤器参数来过滤 API 答案。

【问题讨论】:

    标签: azure azure-api-management


    【解决方案1】:

    您可以在 outbound 块中尝试此策略以过滤 API 答案。

    XML

    <!-- The policy defined in this file demonstrates how to filter data elements from the response payload based on the product associated with the request.
    <!-- The snippet assumes that response content is formatted as JSON and contains root-level properties named "minutely", "hourly", "daily", "flags". -->
    
    <!-- Use https://darksky.net/dev/ API to test this policy. -->
    
    <!-- Copy this snippet into the outbound section. -->
    
    <policies>
      <inbound>
        <base />
      </inbound>
      <backend>
        <base />
      </backend>
      <outbound>
        <base />
        <choose>
          <when condition="@(context.Response.StatusCode == 200 && context.Product.Name.Equals("Starter"))">
            <!-- NOTE that we are not using preserveContent=true when deserializing response body stream into a JSON object since we don't intend to access it again. See details on https://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetBody -->
            <set-body>
              @{
                var response = context.Response.Body.As<JObject>();
                foreach (var key in new [] {"minutely", "hourly", "daily", "flags"}) {
                response.Property (key).Remove ();
               }
              return response.ToString();
              }
        </set-body>
          </when>
        </choose>    
      </outbound>
      <on-error>
        <base />
      </on-error>
    </policies>
    

    可以参考Filter response contentFilter response based on product

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      相关资源
      最近更新 更多