Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating hypermedia links in a custom media-type
    primarykey
    data
    text
    <p>I am currently creating a set of custom media types for a RESTful api (e.g. application/vnd.mycompany.foo+xml) and I'm trying to identify the pros and cons of two different ways of exposing hypermedia links.</p> <p>If I first consider what other media types do probably the best place to start is HTML. Html allows me to create links such as:</p> <pre><code>&lt;image src="http://example.com/image.gif"/&gt; &lt;a href="http://example.com/page.html"/&gt; &lt;form action="http://example.com/page.html"/&gt; &lt;link rel="stylesheet" type="text/css" href="theme.css" /&gt; </code></pre> <p>The interesting thing here is that in some cases there some specific tags that have an url attribute and then there is the generic link tag that using the rel attribute to define the relationship. </p> <p>In AtomPub, there are also a few ways that resources are linked together</p> <pre><code>&lt;collection href="http://example.org/blog/main" &gt; &lt;atom:title&gt;My Blog Entries&lt;/atom:title&gt; &lt;categories href="http://example.com/cats/forMain.cats" /&gt; &lt;/collection&gt; &lt;atom:category scheme="http://example.org/extra-cats/" term="joke" /&gt; &lt;atom:entry&gt; &lt;link rel="edit" href="http://example.org/edit/first-post.atom"/&gt; &lt;/atom:entry&gt; </code></pre> <p>The question that I am asking is when does it make more sense to use a link element with a relationship, and when does it make more sense to add an attribute to an existing element.</p> <p>e.g. the AtomPub links could have been done</p> <pre><code>&lt;collection&gt; &lt;link rel="source" href="http://example.org/blog/main"/&gt; &lt;atom:title&gt;My Blog Entries&lt;/atom:title&gt; &lt;categories&gt; &lt;link rel="source" href="http://example.com/cats/forMain.cats"/&gt; &lt;/categories&gt; &lt;/collection&gt; &lt;atom:category term="joke"&gt; &lt;link rel="scheme" href="http://example.org/extra-cats/"/&gt; &lt;atom:category&gt; &lt;atom:entry edit="http://example.org/edit/first-post.atom"/&gt; </code></pre> <p>As is frequently the case, in writing this question, the answer seems now to be obvious. The required links are exposed as attributes and optional ones as elements. However, I would be very interested in hearing other people's opinions about how they think links should be represented.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload