有人可以解释“超文本作为应用程序状态的引擎"吗?简单来说 [英] Can someone explain “Hypertext as engine of application state" in simple terms

查看:32
本文介绍了有人可以解释“超文本作为应用程序状态的引擎"吗?简单来说的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是我最难理解的 REST 原则.我知道在设计 rest api 时,大部分工作应该用于设计/描述应用程序的超文本.任何指向此主体在现实世界中的应用的指针?原子协议如何应用这个原则?有人可以简单地解释一下如何将其应用于假设的购物车休息 api.

This seems to be the REST principal that I've had the hardest time wrapping my head around. I understand that when desiging a rest api most of the effort should go into designing/describing hypertext for the application. Any pointers to real world applications of this principal ? How does atom protocol apply this principal ? Can some one explain that in simple terms how one would apply that to a hypothetical shopping cart rest api.

推荐答案

考虑自己浏览一个常规网站.当您访问时,您会阅读页面的内容,并根据您阅读的内容和想要执行的操作,点击页面上的各种链接.这确实是超文本作为应用程序状态的引擎"归结为的核心.在这个例子中,应用程序状态是你头脑中的状态和你所在的页面.在此基础上,您遍历更多链接,这会改变您头脑中的应用程序状态.

Consider yourself navigating a regular website. When you visit, you read the contents of the pages, and based on what you've read and what you want to do, you follow various links on the page. That's really the core of what "hypertext as the engine of application state" boils down to. In this example, application state is the state in your head and the page you're on. Based on that, you traverse further links, which alters the application state in your head.

它还有另外一个元素,请注意:另一方面是您不需要猜测这些 URI:页面中应该有足够的上下文来推断 URI(例如应用程序将拥有的信息)的内容类型,以及 URI 模板之类的东西),或者应该存在要遵循的 URI.除此之外,RESTful HTTP 应用程序不应该关心 URI 的结构.

There's one other element to it, mind: the other side of it is that you shouldn't need to guess those URIs: there should be enough context in the page to infer the URIs (such as the information the application would have of the content type, and things like URI template), or the URIs to follow should be present. Beyond that, a RESTful HTTP application shouldn't care about the structure of the URIs.

更新:为了扩展内容,HTML 表单也演示了 HATEOAS.使用 GET 的表单类似于使用 URI 模板.而且 HATEOS 不仅限于使用 HTTP GET 遍历链接:使用 POST 的表单(或其他一些方法,如果浏览器恰好支持它)可以被视为描述要发送到服务器的表示.

UPDATE: To expand on things, HTML forms demonstrate HATEOAS too. Forms that use GET are analogous to the use of URI templates. And HATEOS isn't limited to just traversing links using HTTP GET: forms using POST (or some other method, if the browser just happens to support it) can be though of as describing a representation to send to the server.

这篇关于有人可以解释“超文本作为应用程序状态的引擎"吗?简单来说的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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