滚动
排序
JSON:API 使得在单个请求中检索多个资源成为可能,这些路由称为“集合(collection)”路由。可以通过向基础资源路由发送 GET 请求来获取资源集合,例如 GET /jsonapi/node/article
,并且不包含 UUID。默认情况下,这将包含指定类型的所有资源。
过滤和排序在所有标准资源上默认可用。
请求头
以下请求头在所有 GET 请求中都是必须的,以确保 JSON:API 请求和响应的正确性。
-
Accept: application/vnd.api+json
-
Content-Type: application/vnd.api+json
以下请求头在示例中需要使用:
-
Authorization: Basic YXBpOmFwaQ==
集合排序
按 “created” 排序
按 “created” 时间戳对集合进行排序(默认升序排序)。
简写形式
sort=created
常规形式
sort[sort-created][path]=created
按作者用户名排序
按作者用户名对集合进行降序排序。请注意,前缀的减号 (-) 表示降序。
简写形式
sort=-uid.name
常规形式
sort[sort-author][path]=uid.name
sort[sort-author][direction]=DESC
按多个字段排序
按多个字段对集合进行排序。
简写形式
sort=-created,uid.name
常规形式
sort[sort-created][path]=created
sort[sort-created][direction]=DESC
sort[sort-author][path]=uid.name
文章来源:Drupal 文档。