REST 是 GUI Web 应用程序的不错选择吗?
基于 GUI 的 Web 应用程序可以构建在 GUI 组件、有状态框架(如 Wicket)上,也可以以 RESTful、无状态方式构建,仅在客户端上具有 GUI 状态。
从技术角度来看,REST 看起来是正确的方式,因为它充分利用了 http 的强大功能并带来了高度可扩展的应用程序。但这是有代价的。在许多情况下,复杂的 GUI 需要客户端上有 JavaScript 应用程序。如果应在客户端上维护状态,您必须保持在同一页面上并仅重新加载部分。或者你必须使用隐藏 iframe 的技巧。有时,服务器上会有购物车等伪资源,以实现 RESTful 设计。你必须维护多步对话的中间状态等等......
如果我环顾四周,很少有 RESTful GUI Web 应用程序。这是因为历史原因还是 RESTful 设计在常见场景中效率低下?
GUI based web applications could be build upon a GUI component, stateful framework like Wicket or they could build in a RESTful, stateless way with GUI status only on the client.
From a technical point of view REST looks like the right way since it leverages the full power of http and leads to highly scalable applications. But that comes at a price. Complex GUIs will require a JavaScript application on the client in many cases. You have to stay on the same page and reload only parts, if state should be maintained on the client. Or you have to use tricks with hidden iframes. Sometimes there are pseudo resource like shopping carts on the server, to enable a RESTful design. You have to maintain intermediate state of multi step dialogues and so on ...
If I look around there are very few RESTful GUI webapplications. Is this because of historical reasons or is a RESTful design unproductive in common scenarios?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的答案是主观的,但在我看来,有两个主要障碍阻碍了 RESTful 开发:
在我看来,复杂、丰富的客户端体验将需要一些深入的 JavaScript,无论服务器端实现如何。
这是与传统请求/响应整页到整页设计非常不同的设计。每种设计都有自己的权衡。 REST 设计特别适用于 AJAX 调用,但客户端代码需要仔细设计才能保持可维护性和健壮性。
具有胖客户端的 RESTful 服务器:
然而,正如您提到的,胖客户端有缺点:
My answer is subjective, but in my opinion, two major hurdles hinder RESTful development:
In my opinion, a complex, a rich client-side experience is going to require some in-depth JavaScript, regardless of the server-side implementation.
This is a very different design from the traditional request/response full-page-to-full-page design. Each design has its own trade offs. REST designs work particularly well with AJAX calls, but the client-side code requires careful design to be maintainable and robust.
A RESTful server with a thick-client:
ViewState
sHowever, as you mentioned thick-clients have drawbacks:
恕我直言,RESTful GUI 设计非常高效。您可以利用许多功能,而无需额外的工作来支持极端情况,例如用户重新提交信息、浏览器历史记录(后退和前进)、多个选项卡和窗口。如果我没记错的话,这个网站使用 RESTful UI。
RESTful GUI designs are very productive, IMHO. You can leverage a lot of functionality without extra work to support the corner cases, such as the user resubmitting information, browser history (back and forward) multiple tabs and windows. If I'm not mistaken this site uses a RESTful UI.
REST 是通过观察成功的 Web 应用程序(GUI 和 M2M)的特征来定义的。因此,根据定义,它应该适合这些情况。
我还注意到您提出了有关桌面应用程序与网络应用程序的问题。您可能有兴趣了解 REST 也是构建桌面客户端应用程序的出色架构。我编写了一些桌面客户端,它们从 REST 服务器获取所有数据。
REST was defined by observing characteristic of successful web applications, both GUI and M2M. Therefore by definition it should be appropriate for these cases.
I also noticed you asked a question regarding desktop versus web applications. You may be interested to know that REST is an excellent architecture for building desktop client applications too. I have written a few desktop clients that get all of their data from a REST server.