link 扩展关系类型 URI 在 RESTful API 中应该指向什么?

What should a link extension relation type URI point to in a RESTful API?

我最近一直在设计一个需要 RESTful 的 API,并成功地定义了一个系统,它只使用 HTTP headers 和查询字符串参数来定义元数据,以便 body 的响应可以自由地只是实际的资源数据。

但是我现在正在考虑 HATEOAS 的链接,并且由于希望将所有内容都保留在 HTTP headers 或查询字符串参数中,我决定使用 HTTP Link header 字段。

这提出了一个关于 rel 属性的问题,我找不到直接的答案。

我的想法是,对于 collections 的资源,将在响应中发送的 Links 之一类似于:Link: <https://api.domain.com/things/{id}>; rel="..."

这将允许客户端使用 RFC6570 中定义的简单字符串扩展来为 collection 中的每个资源创建正确的资源 URI,而无需将元数据嵌入到每个资源中资源,客户端不需要知道 URI 模板和资源 ID 以外的任何信息。

但是,我不确定 rel 应该在这里,或者它应该指向什么。

RFC5988中说扩展关系类型必须是URI并且:

Although the URI can point to a resource that contains a definition of the semantics of the relation type, clients SHOULD NOT automatically access that resource to avoid overburdening its server.

我的问题是,RESTful API 中的定义应该是什么样的?

从外观上看,我可以将 rel 做成 https://api.domain.com/media/thing 之类的东西。

那么实际的定义内容应该是什么呢?

看起来它在技术上可以是任何东西,例如带有简短说明的纯文本文档。

这些 rel 属性是否有任何 RESTful 标准,它们应该指向什么?

感谢任何帮助。

Richardson's Maturity Model level 3, rel seems to be representing the name of the published link/relationship. In your case that might translate to curie:thing-by-id (provided you're using curies as suggested in the proposed HAL draft),例如。这个想法是客户端可以通过名称 (rel) 搜索 link,而无需查看实际的 url.

Is there any RESTful standard for these kinds of rel attributes and what they should point to?

我不知道 权威的 答案,但可能值得注意的是 link 关系 registered with IANA 引用了标准文档描述 link.

例如,在注册表中,“item”和“collection”关系都引用了RFC 6573。您会注意到,它非常接近于“带有简短说明的纯文本文档”。

如果您的文档的媒体类型支持锚点,那么您可以使用 link 直接指向辅助资源作为您的 link 关系

Link: <https://api.domain.com/things/2>; rel="https://api.domain.com/link-relations#foo"