json - 任何人都可以对 CURIE 以及如何使用它们提供一个很好的解释吗?

标签 json api hateoas hal-json curie

我看过 HAL specification 中描述的 CURIE .乍一看,它似乎是一种为 URI 提供模板的方法。但是,我也看到它突出地提到它可以用来访问 rel 上的文档。 .哪一个?它仅仅是一种模板机制吗?有没有人有一个好的用例的例子?

另外,以下是否是 CURIE 的合法使用?或者它应该只用于提供有关 rel 的文档?

    { 
        "id": 1,
        "name": "Social Media Bundle",
        "_links": {
            "self": {
                "href": "http://my.api.com/bundles/1"
            },
            "curies": {
                "name": "bundle",
                "href": "http://my.api.com/bundles/1{rel}"
                "templated": true
            },
            "bundle:channels": {
                "href": "/channels"
            }
        }
    }

这里bundle:channels将扩展为 http://my.api.com/bundles/1/channels .

最佳答案

根据 HAL spec 的第 7 页,居里是链接给定资源的文档的建议方法:

Custom link relation types (Extension Relation Types in [RFC5988])
SHOULD be URIs that when dereferenced in a web browser provide
relevant documentation, in the form of an HTML page, about the
meaning and/or behaviour of the target Resource. This will improve
the discoverability of the API.

The CURIE Syntax [W3C.NOTE-curie-20101216] MAY be used for brevity for these URIs. CURIEs are established within a HAL document via a
set of Link Objects with the relation type "curies" on the root
Resource Object. These links contain a URI Template with the token
'rel', and are named via the "name" property.

{
  "_links": {
    "self": { "href": "/orders" },
    "curies": [{
      "name": "acme",
      "href": "http://docs.acme.com/relations/{rel}",
      "templated": true
    }],
    "acme:widgets": { "href": "/widgets" }
  }
}

The above demonstrates the relation "http://docs.acme.com/relations/ widgets" being abbreviated to "acme:widgets" via CURIE syntax.



CURIE spec本身,与记录资源无关,旨在启用紧凑的 URI。

为了回答您的问题,我对规范的解释表明您合法地使用了居里语法,但没有在 HAL 的上下文中使用。

关于json - 任何人都可以对 CURIE 以及如何使用它们提供一个很好的解释吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28154998/

相关文章:

mysql - 从 Perl 格式获取数据并更新 sql 表

java - java mongodb API 中的查询

rest - 使用 HATEOAS 和 Backbone.js

java - Spring HATEOAS 资源支持 -> 域对象

json - 如何修复将 yaml 转换为 JSON 的 YAML 文件中的错误?在此上下文中不允许映射值”

javascript - 如何将 json 对象字符串传递给 javascript 函数?

api - 如何从响应中提取 token 并将其传递给 SOAPUI 中的下一个 api 请求

java - 如何通过 Java API for KML 使用地标 ID 从文件夹中删除 KML 地标?

api - 如何在 REST 超媒体 API 中构建交集?

json - ReactJS 和 django 表单