Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the “link” element in ATOM-feeds?

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>
like image 839
Larry Avatar asked Feb 25 '23 21:02

Larry


1 Answers

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.

like image 193
David Duffett Avatar answered Apr 28 '23 04:04

David Duffett