我看过 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/