如何告诉 HTTP 客户端在哪里可以找到文件的最新版本?

How to tell an HTTP client where to find the latest version of a file?

我正在为数据集设计 HTTP API。我想要永久链接到数据集中文件的每个历史版本,以及重定向到最新版本的 URL。我想添加一个 header 以使客户端能够发现最新的 URL 给定特定版本的 URL:

GET /example/v1

200 OK
Link: </example/latest>; rel="latest"

GET /example/v2

200 OK
Link: </example/latest>; rel="latest"

GET /example/latest

303 See Other
Location: /example/v2

我想知道:rel 参数的值是否比我 could/should 使用的“最新”更好?注意:我知道我应该添加 Link: </example/latest>; rel="canonical",但是 rel="canonical" 捕获的语义与我想要描述的不同。

rel="latest" rel="canonical"
This is where you can find the latest version Hint: if you are a search engine, this is the page I want you to use when grouping a set of similar results

我可能想要服务 Link: </example/v2>; rel="canonical" 甚至 Link: </example/v1>; rel="canonical"

并非不可行

类似问题:

撰写本文时 this list on MDN

中没有合适的条目

is there a better value for the rel parameter than "latest" that I could/should use?

IANA Link Relations registry;在那里,您会找到已注册的 link 关系、non-authoritative 摘要和 link 权威参考。

示例

latest-version

Points to a resource containing the latest (e.g., current) version of the context.

https://www.iana.org/go/rfc5829

RFC 5829 是 Link Relation Types for Simple Version Navigation between Web Resources, and it of course includes a definition for latest-version