链接关系的粒度VS在自定义的媒体类型$ P ​​$ pcision? [英] Link relation granularity vs precision in a custom media type?

查看:202
本文介绍了链接关系的粒度VS在自定义的媒体类型$ P ​​$ pcision?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为一个RESTful API设计定制媒体类型的过程,已经研究的类型和一些对标准的链接关系,语义给我设计了一些转向。

I am in the process of designing a custom media type for a RESTful API, and have researched the types and semantic meaning of the some of the 'standard' link relations to give my design some steer.

为了说明问题,让我们说,我有我可以执行标准读,变化的资源,删除和我使用GET的HTTP成语,PUT方法和DELETE语句来实现这些方法。

To demonstrate the problem let's say that I have a resource that I can perform standard read, change, delete methods on and that I use the HTTP idioms of GET, PUT and DELETE respectively to implement those methods.

我可以合理地(重新)使用编辑链接关系(从的 IANA链接注册)如 RFC5023定义其中规定:

I could reasonably (re)use the "edit" link relation (from the IANA link registry) as defined in RFC5023 which states:

...的价值编辑指定href属性的值
  是一个可编辑成员条目的IRI。当内出现
  原子:入境,在href IRI可用于检索,更新和删除
  资源再$ P $由输入psented ......

"...The value of "edit" specifies that the value of the href attribute is the IRI of an editable Member Entry. When appearing within an atom:entry, the href IRI can be used to retrieve, update, and delete the Resource represented by that Entry...."

在这种方式中,用户代理可以理解,用一个编辑的关系的链接,将允许该资源是GET,PUT和删除。

In this way, the user-agent can understand that a link with a "edit' relationship, will allow the resource to be GET, PUT and DELETEd.

不过,与此存在一个问题,如果资源状态被修改,使得资源现在只支持GET和DELETE操作,编辑关系不再是precise。

However, and herein lies the problem, if the resource state is edited such that the resource now supports only GET and DELETE operations, the "edit" relation is no longer precise.

为了留住precision我需要或者我)选项A:指定支持GET和放大器另一个(化合物)链接关系;只能删除,或ii)选项B:为每一个可能的状态转移个人链接,并使用适当的人,表示允许的状态转移。后一种方法提供了precision,但似乎过于冗长。

In order to retain the precision I need to either i) OPTION A: specify another (compound) link relation that supports GET & DELETE only, or ii) OPTION B: specify individual links for each possible state transfer and use the appropriate ones to indicate the permitted state transfers. The latter approach offers precision but seems overly verbose.

另外,(OPTION C)我可以留在原地的编辑的关系,并接受缺乏precision的即链接会传达的GET,PUT,DELETE的语义,但是用户代理在尝试PUT会遇到了HTTP错误'405 - 不允许的方法。不过,我不开心,这种方法无论是作为这意味着到客户端,不支持状态转换。

Alternatively, (OPTION C) I could leave the "edit" relationship in place and accept the lack of precision i.e. the link would convey the GET, PUT, DELETE semantics but a user-agent attempting a PUT would be met with an HTTP error '405 - Method not allowed'. However, I'm not happy with this approach either as it implies to the client a state transition which is not supported.

总之,问题是什么是平衡链接关系的普遍性和precision最明智的方法是什么?

In summary, the question is what is the most sensible way to balance link relation generality and precision?

推荐答案

在一些严重的调查中,我得出结论,我试图解决错误的问题。而不是HTTP动词的链接关系的定义粒度关注,更细化的问题是'如果HTTP成语(动词)可以合成到链接关系?

After some serious investigation I conclude that I'm trying to solve the wrong problem. Rather than be concerned with the granularity of HTTP verb in the definition of the Link Relation, a more refined question is 'Should the HTTP idioms (verbs) be conflated into the Link Relation?'.

我用过的AtomPub作为该怎么办(用于REST)的链接关系的引用,事实证明这是一个错误。在 AtomPub的电子邮件存档罗伊菲尔丁建议,(在REST术语)的办法来编辑是错误的,并得出结论,这是不必要的。这一观点也意味着,还有其他(HTTP)机制来传达这样的属性,因此,他们在'相对'属性的地方。

I had used AtomPub as a reference of how to do Link Relations (for REST) and it turns out that this was an error. In the AtomPub mail archive Roy Fielding advises that (in REST terms) the approach to 'edit' is wrong and concludes that it is unnecessary. The argument suggests that there are other (HTTP) mechanisms to convey such properties and that they therefore have no place in 'rel' attribute.

其他机制不发的邮件归档明确的,但我怀疑他们包括下列选项:

The other mechanisms aren't made explicit in the mail archive, but I suspect they include the following options:


  1. 让用户代理尝试和检查响应(2XX或4XX),或

  2. 使用OPTIONS询问资源的允许的操作,或

  3. 包括成功的GET请求的允许头传达
    允许资源操作的用户代理。

有趣的是,罗伊认为'允许'头以是超文本的一种形式。

Interestingly, Roy considers the 'Allow' header to be "a form of hypertext".

在总结,回答我的问题是:

In summary, the answer to my own question is:

不要混为一谈HTTP操作成REL的含义

使用(提供)HTTP机制来确定允许的资源操作

编辑:我要补充一点,作为数据接收器而这些规则需要弯曲一点有邮局的一些特殊用途的,但他们是一个特殊的情况下

I should add that there are some special uses of POST as data sink where these rules need to bent a little, but then they are a special case.

这篇关于链接关系的粒度VS在自定义的媒体类型$ P ​​$ pcision?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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