【问题标题】:Is it possible to fetch multiple specific resources with JSON-API?是否可以使用 JSON-API 获取多个特定资源?
【发布时间】:2018-04-24 22:00:58
【问题描述】:

JSON-API provides a way to fetch 资源集合或单个资源。

您可以获取单个资源并指定包含如下关系:

GET /articles/1?includes=author

是否有可能 - 根据规范 - 在一个请求中获得三篇特定的文章?

而不是:

GET /articles/1?includes=author
GET /articles/42?includes=author
GET /articles/67?includes=author

例如(这是为了说明目的而编造的):

GET /articles/1,42,67?includes=author

【问题讨论】:

  • 请注意,指定包含相关资源的查询参数应为include 而不是includes according to spec

标签: json-api


【解决方案1】:

是的,尽管规范对细节是不可知的。它确实为此推荐了查询参数“filter”,并且有一些recommendations。您可以通过获取带有过滤器的 collection 来做到这一点。比如:

GET /articles?filter[id]=1,42,67&include=author

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多