REST 服务的最佳用途是什么? [英] What are the best uses of REST services?

查看:50
本文介绍了REST 服务的最佳用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道像 Facebook 这样的网站现在正在使用 REST 服务,但我想知道其他使用 REST 的应用程序,以及是否存在使用 REST 比其他方法更有保证的特定情况.

I know sites like Facebook are now using REST services, but I am wondering of other applications that use REST and if there are specific situations when the use of REST is more warranted than other methodologies.

推荐答案

REST 与 CRUD 数据服务无关.是的,您可以使用 REST 来执行 CRUD 之类的服务,但这就像说正则表达式用于解析电子邮件地址一样.

REST is not about CRUD data services. Yes you can use REST to do a CRUD like services but that's like saying Regular Expressions are for parsing email addresses.

这里是我迄今为止看过的最好的演示文稿REST 与 SOAP/RPC 的争论.

Here is the best presentation I have seen to-date on the REST versus SOAP/RPC debate.

REST 更侧重于解决分布式客户端/服务器交互,而不是处理服务器到服务器的交互.REST 是关于在用户面前获取内容,以便他们可以选择如何处理它.REST 并不是要创建一个基于 Http 的数据访问层来将您的应用程序逻辑与其数据存储分离.

REST is much more focused towards solving the distributed client/server interaction than it is about dealing with server to server interactions. REST is about getting content in front of the user so they can choose what to do with it. REST is not about creating an Http based data access layer to decouple your application logic from its data store.

Atom Pub 是一个很好的 REST 实现.Netflix API 是最好的商业 REST api 之一.Twitter API 无法满足大多数 RESTful 约束.

Atom Pub is a good REST implementation. The Netflix API is one of the best commercial REST apis. The Twitter API fails most of the RESTful constraints.

如果您想了解有关 REST 的准确信息,请访问以下位置:

If you want accurate information about REST go to these places:

不要听大供应商谈论他们更感兴趣的是让他们的现有产品符合流行语.

Don't listen to the big vendors on the subject they are more interested in making their existing products buzzword compliant.

跟进:

我认为 REST 接口比服务器到服务器交互更适合客户端/服务器交互有几个原因.这只是我的观点,我并不是要声称我以外的任何人都持有这种观点!

There are a few reasons that I believe REST interfaces are more suitable for client/server interactions than server to server interactions. This is just my opinion and I am not trying to claim that this perspective is held by anyone other than me!

当您支持多个客户端访问单个服务器时,缓存和无状态服务器的优势变得更加明显.服务器-服务器通信通常是一对一的,很少有大量服务器与单个服务器通信.

The benefits of caching and a stateless server become far more apparent when you are supporting many clients accessing a single server. A server-server communication is often 1-1 and rarely has a large number of servers communicating with a single server.

REST 是关于松散耦合的.这个想法是您可以继续发展服务器而无需更新客户端.如果您正在考虑在服务器 A 上实现一个 REST 服务,该服务将由位于同一房间的服务器 B 调用,那么松散耦合的好处就会减少.在两台机器上更新一个软件不会让你丧命.

REST is all about loose coupling. The idea is that you can continue to evolve the server without having to update clients. If you are considering implementing a REST service on server A that will be called by server B that is in the same room then the benefits of the loose coupling are diminished. It is not going to kill you to update a piece of software on both machines.

超媒体约束是根据当前应用程序状态为用户提供选择.REST 接口支持对超链接系统的临时探索.服务器-服务器通信往往侧重于实现特定任务.例如处理这批数据.根据计划触发这些事件.本质上,没有用户坐在那里决定要遵循的路径.路径已经根据参数和条件预先确定.

The hypermedia constraint is about giving users choices based on the current application state. REST interfaces support ad-hoc exploration of a hyperlinked system. Server-server communication tends to focus on achieving a specific task. e.g. Process this batch of data. Trigger these events based on a schedule. Inherently there is no user sitting there making decisions as to which path to follow. The path has been predetermined based on parameters and conditions.

在服务器-服务器通信场景中,实现最大吞吐量可能至关重要.二进制协议可能比 Http 更合适.在服务器到服务器类型的通信中,延迟可能很关键.在一端由人驱动的客户端-服务器环境中,性能要求完全不同,我相信 REST 约束更适合这种类型的交互.

In a server-server communication scenario it may be critical to achieve maximum throughput. A binary protocol may be more suitable than Http. Latency may be critical in a server to server type of communication. In a client-server environment where one end is driven by a human the performance requirements are quite different and I believe the REST constraints are more suited to that type of interaction.

REST 建议使用标准媒体类型作为 HTTP 负载.这鼓励偶然地重复使用所提供的服务.我认为重用旨在供客户端应用程序使用的服务的机会比针对其他服务器的服务要多得多.

REST recommends the use of standard media-types as HTTP payloads. This encourages serendipitous re-use of the services provided. I think there are many more opportunities to re-use services that are intended for use by client applications than those aimed at other servers.

在设计 REST 接口时,我喜欢认为服务的使用者是一个受最终用户直接控制的软件.网络浏览器被称为用户代理并非巧合.

When designing REST interfaces I like to think that the consumer of the service is a piece of software that is under the direct control of an end-user. It is no coincidence that a web browser is referred to as a User-Agent.

这篇关于REST 服务的最佳用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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