链接标头与RESTful JSON的链接元素 [英] Link headers vs link elements for RESTful JSON

查看:160
本文介绍了链接标头与RESTful JSON的链接元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用JSON资源构建RESTful / hypermedia API时,似乎我有两个选项来指定资源之间的超媒体关系。


  1. 将链接嵌入JSON文档的正文中。这里的问题是没有用于指定超链接的标准化语法,尽管我看到了许多努力:( HAL,Collection + JSON,JSON-LD,JSON Schema等等)。


  2. 使用HTTP链接头。这是标准化的,因此这似乎比嵌入式链接更具优势。客户只是了解如何理解标准标题和vo,实现了超媒体的好处。


所以,特别是处理JSON资源的上下文,这是要走的路,为什么?

解决方案

使用超媒体JSON格式。虽然链接标题是标准的,但它们很难被采用。它们对于非超媒体的媒体格式更有效。但是既然你可以选择并且可以选择超媒体格式(不像PNG和JPG那样),你应该选择一个并继续前进。



所有的JSON标准是冒泡,直到一个或另一个成为事实上的标准。他们使用得越多,他们得到的事实上就越多。



在我看来,HAL在标准的标准轨道上,我会选择它。 / p>

但无论如何,请使用超媒体格式,因为你可以。


When building a RESTful / hypermedia API with JSON resources, it seems I have two options for specifying the hypermedia relationships between resources.

  1. Embed the links in the body of the JSON document. The problem here is that there isn't a standardized syntax for specifying hyperlinks, although I see a number of good efforts: (HAL, Collection+JSON, JSON-LD, JSON Schema to name a few).

  2. Use HTTP Link headers. This is a standardized, so this seems to have an advantage over embedded links. Clients just understand how to make sense of the standard header and voila, hypermedia goodness is achieved.

So, specifically in the context of handling JSON resources, which is the way to go and why?

解决方案

Go with a hypermedia JSON format. While Link Headers are standard, they're poorly adopted. They're really more valid for media formats that are not hypermedia. But since you have a choice and can choose a hypermedia format (unlike, say, PNG vs JPG), you should simply choose one and move forward.

All of the JSON standard are bubbling about until one or another becomes a "de facto" standard. The more they're used, the more "de facto" they get.

Seems to me that HAL is on a solid Standards track, and I would pick that.

But either way, go with a hypermedia format because you can.

这篇关于链接标头与RESTful JSON的链接元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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