azure - Azure API 管理。如何添加 URL 路径过滤
问题描述
我正在 Azure 中使用 API 管理构建 API。现在我不确定如何配置策略,所以我可以使用 URL 过滤器参数来过滤 API 答案。
解决方案
您可以在出站块中尝试此策略以过滤 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 content和Filter response based on product
推荐阅读
- python - 将 openpyxl Excel 工作表更改为横向
- r - 如何对数据框列的频率分布进行排序
- php - 将 2 个数组表加在一起
- java - 打印给定元素数组的所有可能组合
- javascript - Javascript 加载 FBX 6100 和 FBX SDK 2011(3D 文件)
- vba - 通过行循环宏
- node.js - 从 Tweet 对象发送图片数据会导致模板中的图像损坏
- google-cloud-datastore - 如何使用多个工作人员加快批量导入谷歌云数据存储的速度?
- java - 如何读取 brotli 压缩字符串?
- android-studio - android studio,修复安卓缓存问题