谁能很好地解释 CURIE 以及如何使用它们?
Can anyone provide a good explanation of CURIEs and how to use them?
我看过 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 页,curies 是一种建议的方法,通过它 link 给定资源的文档:
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 的上下文中。
CURIE 是非 XML 语言中 QName 的替代品,它提供命名空间功能,用于使用基于 prefix/suffix 的 shorthand 描述 URL 关系] 语义数据(RDFa、JSON-LD、YAML 等)中的映射,而不依赖于 XML 名称空间。
The semantic web specifies this via Vocabulary Documents, in which a prefix is associated with a document, and a suffix is used to create an IRI based on this vocabulary. For example, the IRI http://xmlns.com/foaf/0.1/ specifies a Vocabulary Document, and name is a term in that vocabulary. Join the two items together and you have an unambiguous identifier for a vocabulary term. The Compact URI Expression, or short-form, is foaf:name and the expanded-form is http://xmlns.com/foaf/0.1/name. This vocabulary term identifies the given name for something, for example - a person's name.
例如:
If in RDF I want to use the Dublin Core creator property, then all I need do is this:
dc:creator
and provided that I have the dc namespace prefix defined as http://purl.org/dc/elements/1.1/, I have effectively represented the following URI:
http://purl.org/dc/elements/1.1/creator
在 HTML 中看起来像这样:
<div prefix="dc:http://purl.org/DC/elements/1.0">
<a property="dc:creator" href="http://example.com">IANA</a>
</div>
参考资料
我看过 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 页,curies 是一种建议的方法,通过它 link 给定资源的文档:
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 的上下文中。
CURIE 是非 XML 语言中 QName 的替代品,它提供命名空间功能,用于使用基于 prefix/suffix 的 shorthand 描述 URL 关系] 语义数据(RDFa、JSON-LD、YAML 等)中的映射,而不依赖于 XML 名称空间。
The semantic web specifies this via Vocabulary Documents, in which a prefix is associated with a document, and a suffix is used to create an IRI based on this vocabulary. For example, the IRI http://xmlns.com/foaf/0.1/ specifies a Vocabulary Document, and name is a term in that vocabulary. Join the two items together and you have an unambiguous identifier for a vocabulary term. The Compact URI Expression, or short-form, is foaf:name and the expanded-form is http://xmlns.com/foaf/0.1/name. This vocabulary term identifies the given name for something, for example - a person's name.
例如:
If in RDF I want to use the Dublin Core creator property, then all I need do is this:
dc:creator
and provided that I have the dc namespace prefix defined as http://purl.org/dc/elements/1.1/, I have effectively represented the following URI:
http://purl.org/dc/elements/1.1/creator
在 HTML 中看起来像这样:
<div prefix="dc:http://purl.org/DC/elements/1.0">
<a property="dc:creator" href="http://example.com">IANA</a>
</div>
参考资料