“链接”是什么? ATOM 提要中的元素?

发布于 2024-10-20 14:56:39 字数 838 浏览 6 评论 0原文

有人可以帮助我了解“链接”标签在 ATOM 提要中的用途吗?

  • 它们指向物理资源,还是只是像标识符一样?
  • 开头的链接 URL 和每个“入口”块的链接 URL 有什么区别?
  • 这个linkURL 是必须的吗?

任何有关此的信息将不胜感激!

我在下面提供了示例代码片段。

<?xml version="1.0"?>
<atom:feed>

  <link rel="self" href="http://publisher.example.com/happycats.xml" />
  <updated>2008-08-11T02:15:01Z</updated>

  <!-- Example of a full entry. -->
  <entry>
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <content>
      What a happy cat. Full content goes here.
    </content>
  </entry>

Could someone please help me understand what the “link” tags are used for within an ATOM feed?

  • Do they point to a physical resource, or just like an identifier?
  • What is the difference between link URLs in the beginning and for each “entry” block?
  • Is it compulsory to have this linkURL?

Any information regarding this would be much appreciated!

I have provided an example snippet of code below.

<?xml version="1.0"?>
<atom:feed>

  <link rel="self" href="http://publisher.example.com/happycats.xml" />
  <updated>2008-08-11T02:15:01Z</updated>

  <!-- Example of a full entry. -->
  <entry>
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <content>
      What a happy cat. Full content goes here.
    </content>
  </entry>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掐死时间 2024-10-27 14:56:39

Atom 是一种联合格式,可供通过超媒体采用 ReSTful 通信的应用程序使用。它非常适合发布提要,不仅适用于博客,还可以用于分布式应用程序(例如,将事件发布到系统的其他部分),以利用 HTTP 的优势(缓存、可扩展性等)和使用 REST 涉及的解耦。

Atom 中的元素称为链接关系,可以向提要的使用者指示许多内容:

  • rel="self" 通常指示当前元素(在您的情况下) ,提要本身)代表一个实际资源,这是该资源的 URI
  • rel="via" 可以识别提要中信息的原始来源或提要中的条目
  • rel="alternate" 指定指向同一资源(提要或条目)的替代表示的链接
  • rel="enclosure" 可能意味着链接到的资源旨在被下载和缓存,因为它可能很大
  • rel="lated" 表示链接以某种方式与当前提要或条目相关
  • ATOM 提供商还可以指定他们自己的链接出现原因,并且提供自定义 rel

通过以这种方式提供相关资源的链接,您可以解耦系统 - 系统需要了解的唯一 URI 是 1 个入口点,从那时起,其他操作将提供给消费者通过这些链接关系。这些链接有效地告诉消费者,他们可以使用这些链接对与其相关的条目执行操作或检索数据。

我可以推荐一本关于 REST 的好书,它深入了解 Atom 是 REST 实践,作者:Jim Webber、Savas Parastatidis 和 Ian Robinson。

Atom is a syndication format that can be used by applications employing ReSTful communication through hypermedia. It's very good for publication of feeds, which is not only for blogs but can also be used in distributed applications (for example, for publishing events to other parts of a system) to utilise the benefits of HTTP (caching, scalability, etc) and the decoupling involved in using REST.

elements in Atom are called link relations and can indicate to the consumer of the feed a number of things:

  • rel="self" normally indicates that the current element (in your case, the feed itself) represents an actual resource, and this is the URI for that resource
  • rel="via" can identify the original source of the information in the feed or the entry within the feed
  • rel="alternate" specifies a link to an alternative representation of the same resource (feed or entry)
  • rel="enclosure" can mean that the linked to resource is intended to be downloaded and cached, as it may be large
  • rel="related" indicates the link is related to the current feed or entry in some way
  • A provider of ATOM could also specify their own reasons for a link to appear, and provide a custom rel value

By providing links to related resources in this way you can decouple systems - the only URI the system needs to know about is 1 entry point, and from then on other actions are provided to the consumer via these link relations. The links effectively tell the consumer that they can use these links to either take actions on or retrieve data for the entry they are related to.

A great book I can recommend for REST which goes into depth about Atom is REST in Practice by Jim Webber, Savas Parastatidis and Ian Robinson.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文