REST 客户端实施是否接受 HATEOAS 约束?

发布于 2024-07-29 05:46:51 字数 465 浏览 4 评论 0原文

有谁知道 REST 客户端的实现包含 超媒体作为应用程序状态的引擎 (HATEOAS)?

从其记录方式来看,Sun Cloud API 似乎是一个不错的候选者,并且 < a href="http://blogs.oracle.com/craigmcc/entry/why_hateoas" rel="noreferrer">作者的声明,大意是 Ruby、Java 和 Python 实现正在开发中。 但到目前为止我还没有发现代码的踪迹。

我正在寻找任何东西 - 即使是部分实现也会有帮助。

Does anybody know of an implementation of a REST client that embraces the constraint of Hypermedia as the Engine of Application State (HATEOAS)?

The Sun Cloud API seems to be a good candidate, judging from the way it's documented and a statement by the author to the effect that Ruby, Java, and Python implementations were in the works. But so far I've found no trace of the code.

I'm looking for anything - even a partial implementation would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

以往的大感动 2024-08-05 05:46:52

Restfulie 是一个 Ruby、Java 和 C# 框架,旨在支持构建采用 HATEOAS 的客户端和服务器。 我没用过,但看起来确实很有趣。

这是来自他们的java项目的一些示例代码:

Order order = new Order();

// place the order
order = service("http://www.caelum.com.br/order").post(order);

// cancels it
resource(order).getTransition("cancel").execute();

同样,我不确定这到底是做什么的,或者说它在实践中效果如何,但它看起来确实很有趣。

Restfulie is a Ruby, Java, and C# framework which aims to enable building clients and servers which employ HATEOAS. I haven't used it, but it does look interesting.

Here's some example code from their java project:

Order order = new Order();

// place the order
order = service("http://www.caelum.com.br/order").post(order);

// cancels it
resource(order).getTransition("cancel").execute();

Again, I'm not sure exactly what this does, or how well it works in practice, but it does seem intriguing.

得不到的就毁灭 2024-08-05 05:46:52

REST HTTP 和 HATEOAS 的问题在于,没有通用的方法来指定链接,因此很难跟踪链接,因为它们的结构可能会从一个服务提供商更改为另一个服务提供商。 有些会使用 其他人会使用链接的专有结构。 。 它不像 HTML 或 Atom 那样,链接是定义的标准的一部分。

客户端无法知道您的表示中的链接是什么,因为它不知道您的媒体类型,除非存在链接的标准或常规表示

The problem with REST HTTP and HATEOAS is that there is no common approach to specifying links so it is hard to follow links since their structure might change from a service provider to another. Some would use <link href="..." /> others would use proprietary structure for of links ex. <book href="..." />. It is not like in HTML or atom were link are part of a standard defined.

A client can't know what a link is in your representation is it doesn't know your media type unless there is a standard or conventional representation of a link

咋地 2024-08-05 05:46:52

HATEOAS 设计原则(REST 也是一组设计原则)意味着每个资源最多应该有一个固定的 URL。

其他所有相关内容都应该可以通过“超媒体”链接从该 URL 动态发现。

我刚刚在此处创建了一个维基百科存根

The HATEOAS design principle (REST is a set of design principles also) means that each resource should have at most a single fixed URL.

Everything else related should be discoverable dynamically from that URL through "hypermedia" links.

I just started a wikipedia stub here

我只土不豪 2024-08-05 05:46:52

与此同时,还有 Spring HATEOAS 项目。 它还有一个客户端实现:
https://docs.spring.io/spring-hateoas /docs/current/reference/html/#client

Map<String, Object> parameters = new HashMap<>();
parameters.put("user", 27);

Traverson traverson = new Traverson(URI.create("http://localhost:8080/api/"), MediaTypes.HAL_JSON);
String name = traverson
    .follow("movies", "movie", "actor").withTemplateParameters(parameters)
    .toObject("$.name");

In the meanwhile, there is the Spring HATEOAS project. It has also a client implementation:
https://docs.spring.io/spring-hateoas/docs/current/reference/html/#client

Map<String, Object> parameters = new HashMap<>();
parameters.put("user", 27);

Traverson traverson = new Traverson(URI.create("http://localhost:8080/api/"), MediaTypes.HAL_JSON);
String name = traverson
    .follow("movies", "movie", "actor").withTemplateParameters(parameters)
    .toObject("$.name");
梦中的蝴蝶 2024-08-05 05:46:51

您应该首先查看的是常见的网络浏览器。 这是接受 HATEOAS(至少在某种程度上)的客户的标准。

这就是超媒体的工作原理。 它非常简单,几乎令人痛苦:

  1. 您将浏览器指向 http://pigs-are-cool.org/
  2. 浏览器会加载 HTML 页面、图像、CSS 等。
    • 此时,应用程序(您的浏览体验)位于特定的 URI。
    • 浏览器正在显示该 URI 的内容
  3. 您在应用程序中看到一个链接
  4. 您单击该链接
  5. 浏览器跟随该链接
    • 此时,应用程序位于不同的 URI
    • 浏览器正在显示新 URI 的内容

现在简要说明这两个术语与 Web 浏览体验的关系:

  • 超媒体 = 带有嵌入链接的 HTML 页面
  • 应用程序状态 = 您在任何时间点在浏览器中看到的内容。

因此,HATEOAS 实际上描述了当您从一个网页转到另一个网页时,网络浏览器中会发生什么:

带有嵌入链接的 HTML 页面驱动您在任何时间点在浏览器中看到的内容

HATEOAS 一词只是这种浏览体验的抽象。

RESTful 客户端应用程序的其他示例包括:

  • RSS 和 Feed 阅读器。 用户提供的链接
  • 他们遍历大多数 AtomPub 博客客户端 。 他们只需要服务文档的 URI,然后从那里找到上传图像和博客文章、搜索等的位置。
  • 可能是 Google Gadgets(以及类似的),但它们只是不同皮肤的浏览器。
  • 网络爬虫也是 RESTful 客户端,但它们是一个利基市场。

RESTful 客户端软件的一些特征:

  • 客户端可以与任何服务器一起工作,前提是它使用某些 URI 进行初始化并且服务器以预期结果进行响应(例如,对于 Atom 博客客户端,Atom 服务文档)。
  • 除了在运行时可以找到的内容之外,客户端对服务器如何设计其 URI 一无所知
  • 客户端知道足够的媒体类型和链接关系以了解服务器所说的内容(例如 Atom 或 RSS)
  • 客户端使用嵌入式链接来查找其他内容资源; 有些是自动的(如 ),有些是手动的(如 )。

它们通常是由用户驱动的,可以正确地称为“用户代理”,但 GoogleBot 除外。

The very first thing you should look at is the common web browser. It is the standard for a client that embraces HATEOAS (at least to some degree).

This is how Hypermedia works. It's so simple that it's almost painful:

  1. you point your browser to http://pigs-are-cool.org/
  2. the browser loads the HTML page, images, CSS and so on.
    • At this point, the application (your browsing experience) is at a specific URI.
    • The browser is showing the content of that URI
  3. you see a link in the application
  4. you click the link
  5. the browser follows the link
    • at this point, the application is at a different URI
    • The browser is showing the content of the new URI

Now for a short explanation of how the two terms relate to the web browsing experience:

  • Hypermedia = HTML pages with the embedded links
  • Application state = What you're seeing in the browser at any point in time.

So HATEOAS actually describes what happens in a web browser when you go from web page to web page:

HTML pages with embedded links drive what you see in the browser at any point in time

The term HATEOAS is just an abstraction of this browsing experience.

Other examples of RESTful client applications include:

  • RSS and Feed readers. They traverse links given to them by users
  • Most AtomPub blog clients. They need merely a URI to a services document, and from there they find out where to upload images and blog posts, search and so on.
  • Probably Google Gadgets (and similar), but they're merely browsers in a different skin.
  • Web crawlers are also RESTful clients, but they're a niche market.

Some characteristics of RESTful client software:

  • The client works with with any server, given that it is primed with some URI and the server responds with an expected result (e.g. for an atom blog client, an Atom services document).
  • The client knows nothing about how the server designs its URIs other than what it can find out at runtime
  • The client knows enough media types and link relations to understand what the server is saying (e.g. Atom or RSS)
  • The client uses embedded links to find other resources; some automatically (like <img src=) some manually (like <a href=).

Very often they are driven by a user, and can correctly be termed "user agents", except for, say GoogleBot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文