c# - JSON:API 规范过滤参数与 Flurl HTTP
问题描述
我们在 API 上使用 JSON:API 规范。目前在 C# 中使用 Flurl 将过滤器参数格式化为规范存在问题。
例子:
var url = await Helpers.GetAPIPath()
.AppendPathSegment("orders")
.WithOAuthBearerToken(Helpers.GetAPIToken())
.SetQueryParams(new {
filters = "[work_orders]=true,[status]=pending_approval",
include = "shipping-address,inventory-items.part"
}).GetAsync();
这产生/orders?filters[work_orders]=true,[status]=pending_approval&include=shipping-address,inventory-items.part
这是关于 JSON:API 请求的文档,带有多个过滤器https://jsonapi.org/recommendations/#filtering
如何构建类似于filter[work_orders]=true,filter[status]=pending_approval
JSON:API 规范的过滤器?
任何帮助深表感谢!
解决方案
这个片段能够实现正确的过滤参数。不确定是否有更清洁的方法来实现这一点,但到目前为止它正在工作!
var orderResponse = await Helpers.GetAPIPath()
.AppendPathSegment("orders")
.WithOAuthBearerToken(Helpers.GetAPIToken())
.SetQueryParam("filter[work_orders]=true")
.SetQueryParam("filter[status]=pending_approval")
.SetQueryParams(new {
include = "shipping-address,inventory-items.part",
}).GetAsync();
推荐阅读
- uwp - StackPanel ,边框在 UWP 中无法正确绘制?
- python - 如何将c ++中的重心坐标计算转换为python?
- swift - 在重新加载数据时维护 UISwipeActionsConfiguration
- sikuli - 知道如何使用 Sikulix 命令在 word 中插入表格(包含行和列)吗?
- vba - 使用VBA根据表id将大量附件导入Microsoft Access
- web-scraping - 滚动到下一页并提取数据
- c - 如何设置一个只有 makefile 和源代码的 C 程序,以便使用 QtCreator 进行调试?
- python - SQLalchemy:在两列或多列中选择满足条件的行
- ignite - Apache ignite 客户端节点重新连接出现错误 org.apache.ignite.internal.processors.cache.CacheStoppedException:无法执行缓存操作
- javascript - 在表格内搜索元素时表格标题保持固定