在自定义媒体类型中创建超媒体链接 [英] Creating hypermedia links in a custom media-type

查看:161
本文介绍了在自定义媒体类型中创建超媒体链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为RESTful api创建一组自定义媒体类型(例如application / vnd.mycompany.foo + xml),我试图找出两种不同的暴露超媒体链接方式的优缺点。 / p>

如果我首先考虑其他媒体类型可能最好的起点是HTML。 Html允许我创建链接,例如:

 < image src =http://example.com/image.gif /> 
< a href =http://example.com/page.html/>
< form action =http://example.com/page.html/>
< link rel =stylesheettype =text / csshref =theme.css/>

这里有趣的是,在某些情况下,某些特定标签具有url属性然后在那里是使用rel属性定义关系的通用链接标记。



在AtomPub中,还有一些资源链接在一起的方式

 < collection href =http://example.org/blog/main> 
< atom:title>我的博客条目< / atom:title>
< categories href =http://example.com/cats/forMain.cats/>
< / collection>

< atom:category scheme =http://example.org/extra-cats/term =joke/>
< atom:entry>
< link rel =edithref =http://example.org/edit/first-post.atom/>
< / atom:entry>

我要问的问题是什么时候使用带关系的链接元素更有意义,何时将属性添加到现有元素更有意义。



例如AtomPub链接可以完成

 < collection> 
< link rel =sourcehref =http://example.org/blog/main/>
< atom:title>我的博客条目< / atom:title>
< categories>
< link rel =sourcehref =http://example.com/cats/forMain.cats/>
< / categories>
< / collection>

< atom:category term =joke>
< link rel =schemehref =http://example.org/extra-cats//>
< atom:category>
< atom:entry edit =http://example.org/edit/first-post.atom/>

通常情况下,在写这个问题时,答案似乎显而易见。必需的链接作为属性公开,可选的链接作为元素公开。但是,我会非常有兴趣听取其他人对于如何表示链接的看法。

解决方案

我喜欢什么 XHTML 2 每个元素都可以有一个链接



为什么不利用 XLink 能够实现相同的功能吗?这样,无需选择。


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.

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:

<image src="http://example.com/image.gif"/>
<a href="http://example.com/page.html"/>
<form action="http://example.com/page.html"/>
<link rel="stylesheet" type="text/css" href="theme.css" />

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.

In AtomPub, there are also a few ways that resources are linked together

<collection href="http://example.org/blog/main" >
         <atom:title>My Blog Entries</atom:title>
         <categories href="http://example.com/cats/forMain.cats" />
</collection>

<atom:category scheme="http://example.org/extra-cats/" term="joke" />
<atom:entry>
   <link rel="edit" href="http://example.org/edit/first-post.atom"/>
</atom:entry>

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.

e.g. the AtomPub links could have been done

<collection>
      <link rel="source" href="http://example.org/blog/main"/>
         <atom:title>My Blog Entries</atom:title>
         <categories>
                <link rel="source" href="http://example.com/cats/forMain.cats"/>
         </categories>
</collection>

<atom:category term="joke">
     <link rel="scheme" href="http://example.org/extra-cats/"/>
<atom:category>
<atom:entry edit="http://example.org/edit/first-post.atom"/>

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.

解决方案

What I liked about XHTML 2 was that every element could have a link.

Why not leverage XLink to enable the same funcitonality? That way, no need to choose.

这篇关于在自定义媒体类型中创建超媒体链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆