为什么我们需要REST Web服务? [英] Why do we need RESTful Web Services?

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

问题描述

我要学习REST Web服务(这是更好地说,我必须这样做,因为这是CS硕士学位计划的一部分)。

我读过维基百科中的一些信息,我也看过关于REST在Sun开发者网络的文章,我看到它是不容易的技术,有构建RESTful应用程序的特殊架构,而且它经常被比较SOAP Web服务和程序员都应该了解什么时候使用SOAP和REST时可能是很好的办法。

我记得几年前SOAP是非常普遍的(时尚?)和项目SOAP不得不在每一个良好的CV present。但在实践中,它被用来很少和实现非常简单的目的。

在我看来,这REST是另一种时尚的最后一个字(或我可​​以完全错误的,因为我还没有见过REST在实践中)。

你能不能给我进行了REST应该使用一些例子,为什么我们不能没有休息(或为什么我们应该花更多的时间做同样不休息)做?

UPD :可惜的是我看不到任何具体的参数,可以吹我的脑海里第一的意见。让我认为REST是真棒技术!

我想看到这样的答案:


  

我正在开发另一项复杂的
  HelloWorld应用程序,我们需要
  转让地段/微小的数据和我的
  REST提出解决我的工友:


  
  

&ndash的;哦,该死的!强尼,我们应该
  当然使用REST实现
  这个程序
&ndash的!;是的,比利,我们
  可以使用REST,但我们会更好的使用
  肥皂。相信我,因为我知道的东西
  关于发展的HelloWorld
  应用
&ndash的。但是,SOAP是
  老式的技术从上
  世纪,我们可以用更好
  1
&ndash的。比利,你准备好了吗
  到了3天用于试验
  休息?我们可以在2 SOAP这样做
  小时..
&ndash的;是,我确定
  我们会花更多的时间来
  达到相同的安全/性能/
  /可扩展性/任何其他人使用SOAP。
  我敢肯定,HelloWorld的应用
  应与REST只开发
  从现在开始。



解决方案

应该如果是你非常重要的使用REST的最小化分布式应用程序的客户端和服务器组件之间的耦合

如果你的服务器将被使用的许多不同的客户端,你不拥有控制权,这可能是这种情况。这也可能是,如果你希望能够到的情况下的更新服务器定期,而无需更新客户端软件。

我可以向你保证,实现耦合这种低级别的不容易做到。关键是要遵守所有REST的约束才能成功。保持一个纯粹的无状态的连接是困难的。选择正确的介质类型和数据挤进格式是棘手的。创建自己的介质类型会更难。

适应丰富的服务器行为纳入统一的HTTP接口可能会造成混淆,有时相较于相对简单的RPC方法似乎迂腐。

尽管困难重重,带来的好处是,你有一个客户端开发者应该能够很容易地理解,由于一贯使用的HTTP协议的服务。该服务应为容易发现,由于超媒体并在客户端应该是非常的抵御服务器

上的变化

超媒体和好处会话状态的避免使负载平衡简单和服务分区可行。严格符合HTTP规则,使像调试器和缓存代理天底下工具的可用性。

更新


  

在我看来,这是REST另一个
  时尚的最后一个字(或我可​​以
  完全错误的,因为我还没有
  在实践中看到REST)。


我认为REST已成为时尚,因为人们试图做SOA型项目已经发现,使用SOAP堆栈他们没有意识到被许诺的好处。不断有人义无反顾地网络作为简单集成方法的一个例子。不幸的是,我认为人们低估了规划和远见的进​​入创造了网络的数量和他们过分简单化需要做的,以允许它在网络上出现的那种偶然重用的东西。

你说你从来没有见过在实践中休息,但如果你使用的网络浏览器不可能是真的。 Web浏览器是一个REST客户端。


  • 为什么你不需要做一个浏览器
    更新当有人改变一些HTML
    在一个网站?

  • 为什么我可以添加一个全新的集
    网页到网站,客户
    仍然可以访问这些新页面
    没有更新?

  • 为什么我没有需要提供
    服务描述语言来
    Web浏览器来告诉它当它
    到的 http://example.org/images/cat 的那
    返回类型将JPEG图像
    当你去
    http://example.org/description/cat
    返回类型将是text / html的?

  • 为什么可以使用Web浏览器访问
    站点不存在时的
    浏览器被释放?如何能
    客户知道这些网站?

这听起来像是空洞的问题,但如果你知道答案,那么你就可以开始看到是所有关于REST。
看着计算器对REST的更多的实惠。当我在看一个问题,我可以书签该页面或发送链接给好友,他能够看到相同的信息。他没有通过该网站浏览,发现问题。

计算器使用各种服务的OpenID认证,gravatar.com的头像图片,谷歌分析和Quantserve的分析资料。这种多公司的整合是东西在 SOAP世界唯一的梦想的类型。一个最好的例子是被用来驱动StackOverflow的UI了jQuery库是从谷歌的内容分发网络检索到的事实。说了这么能直接在客户端(即Web浏览器),以从第三方网站来提高性能下载code,这一事实证明了Web客户端和服务器之间的低耦合。

这是在工作中REST架构的例子。

现在一些网站/应用程序做的打破REST ,然后按预期的浏览器不工作的规则。


  • 臭名昭著的后退按钮问题
    通过使用服务器侧引起
    会话状态。

  • 负载均衡可以成为一个痛苦的时候
    你有服务器端的会话状态。

  • Flash应用程序通常prevent的
    从具体识别网址
    再presentation。

  • ,打破了网络的另一个问题
    浏览器是一致性差
    媒体类型的标准。我们听到的所有的
    关于IE6需要如何的时候
    杀害。问题存在着
    标准是不恰当的操作,
    或者被忽略无论出于何种原因。

  • 使用登录会话是
    许多安全漏洞的来源。

REST是无处不在。它是,使得它很好地工作在网络的一部分。如果你想建立分布式应用程序,可以扩展,比如Web,要适应变化,如网络和促进再利用的网络已经完成,然后按照构建Web浏览器时,他们也做了同样的规则。

I'm going to learn RESTful web services (it's better to say that I'll have to do this because it's a part of CS master degree program).

I've read some info in Wikipedia and I've also read an article about REST at Sun Developer Network and I see that it's not easy technology, there are special frameworks for building RESTful apps, and it's often being compared to SOAP web services and programmer should understand when to use SOAP and when REST could be nice approach.

I remember that several years ago SOAP was very popular (fashionable?) and item 'SOAP' had to be present in every good CV. But in practice it was used very rarely and for achieving very simple purposes.

It seems to me that REST is another 'last word of fashion' (or I can be totally wrong because I haven't ever seen REST in practice).

Can you give me some examples were REST should be used and why we can't do the same without REST (or why we should spend much more time to do the same without REST)?

UPD: Unfortunatelly I can't see any concrete arguments which can blow my mind in first comments. Make me think that REST is awesome technology!

I'd like to see answers like this:

I was developing another complex HelloWorld application and we need to transfer lots of / tiny data and I proposed REST solution to my workmate:

– Oh, damn! Jonny, we should certainly use REST for implementing this app!
– Yes, Billy, we can use REST, but we would better use SOAP. Trust me 'cause I know something about developing HelloWorld applications.
– But SOAP is old-fashioned technology from the last century and we can use better one.
– Billy, are you ready to spent 3 days for experimenting with REST? We can do this with SOAP in 2 hours..
– Yes, I'm sure that we'll spent even more time to achieve the same security/performance/ /scalability/whatever else with SOAP. I'm sure that HelloWorld applications should be developed only with REST from now.

解决方案

REST should be used if it is very important for you to minimize the coupling between client and server components in a distributed application.

This may be the case if your server is going to be used by many different clients that you do not have control over. It may also be the case if you want to be able to update the server regularly without needing to update the client software.

I can assure you that achieving this low level of coupling is not easy to do. It is critical to follow all of the constraints of REST to succeed. Maintaining a purely stateless connection is difficult. Picking the right media-types and squeezing your data into the formats is tricky. Creating your own media types can be even harder.

Adapting rich server behaviour into the uniform HTTP interface can be confusing and at times appears pedantic in comparison to the relatively straightforward RPC approach.

Despite the difficulties, the benefits are that you have a service that a client developer should be able to easily understand due to the consistent use of the HTTP protocol. The service should be easily discoverable due to hypermedia and the client should be extremely resilient to changes on the server.

The benefits of hypermedia and the avoidance of session state makes load balancing simple and service partitioning feasible. The strict conformance to HTTP rules make the availability of tools like debuggers and caching proxies wonderful thing.

Update

It seems to me that REST is another 'last word of fashion' (or I can be totally wrong because I haven't ever seen REST in practice).

I think REST has become fashionable because people attempting to do SOA type projects have found that using the SOAP stack they are not realizing the benefits that were promised. People keep turning back to the web as an example of simple integration methodologies. Unfortunately, I think people underestimate the amount of planning and foresight that went into creating the web and they oversimplify what needs to be done to allow the kind of serendipitous reuse that does occur on the web.

You say that you have never seen REST in practice, but that cannot possibly be true if you ever use a web browser. The web browser is a REST client.

  • Why do you not need to do a browser update when someone changes some html on a web site?
  • Why can I add a complete new set of pages to a web site and the "client" can still access those new pages without an update?
  • Why do I not need to provide a "service-description-language" to the web browser to tell it when it goes to http://example.org/images/cat that the return type will be a jpeg image and when you go to http://example.org/description/cat the return type will be text/html?
  • Why can I use a web browser to visit sites that did not exist when the browser was released? How can the client know about these sites?

These may sound like inane questions, but if you know the answer, then you can start to see what REST is all about. Look at StackOverflow for more benefits of REST. When I am looking at a question, I can bookmark that page or send the url to a friend and he can see the same information. He doesn't have to navigate through the site to find that question.

StackOverflow uses a variety of OpenId services for authentication, gravatar.com for avatar images, google-analytics and Quantserve for analytical information. This kind of multi-company integration is the type of thing the SOAP world only dreams of. One of the best examples is the fact that the jQuery libraries that are used to drive the StackOverflow UI are retrieved from Google's Content Delivery Network. The fact that SO could direct the client (i.e. your web browser) to download code from a third-party site to improve performance is testament to the low coupling between web client and server.

These are examples of a REST architecture at work.

Now some web sites / applications do break the rules of REST and then the browser does not work as expected.

  • The infamous back button problem is caused by using server side session state.
  • Load balancing can become a pain when you have server side session state.
  • Flash applications often prevent the URL from specifically identifying a representation.
  • The other problem that breaks web browsers is poor conformance to media-type standards. We hear all of the time about how IE6 needs to be killed. The problem there is that standards were not properly followed, or were ignored for whatever reason.
  • The use of login sessions are the source of many security holes.

REST is everywhere. It is the part of the web that makes it work well. If you want to build distributed applications that can scale like the web, be resilient to change like the web and promote re-use as the web has done, then follow the same rules they did when building web browsers.

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

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