??xml version="1.0" encoding="utf-8" standalone="yes"?>yiren22亚洲综合,久久久久久久免费视频了,久久精品视频网http://www.aygfsteel.com/alex/category/19422.html不求多得,只求一? about java,hibernate,spring,design,database,Ror,ruby,快速开?lt;br/><br/> 最q关心的内容关键?RoR zh-cnMon, 04 Jun 2007 00:06:07 GMTMon, 04 Jun 2007 00:06:07 GMT60rails 安装与升U?/title><link>http://www.aygfsteel.com/alex/archive/2007/06/04/121709.html</link><dc:creator>Alex</dc:creator><author>Alex</author><pubDate>Sun, 03 Jun 2007 16:18:00 GMT</pubDate><guid>http://www.aygfsteel.com/alex/archive/2007/06/04/121709.html</guid><wfw:comment>http://www.aygfsteel.com/alex/comments/121709.html</wfw:comment><comments>http://www.aygfsteel.com/alex/archive/2007/06/04/121709.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/alex/comments/commentRss/121709.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/alex/services/trackbacks/121709.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://www.aygfsteel.com/alex/archive/2007/06/04/121709.html'>阅读全文</a><img src ="http://www.aygfsteel.com/alex/aggbug/121709.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/alex/" target="_blank">Alex</a> 2007-06-04 00:18 <a href="http://www.aygfsteel.com/alex/archive/2007/06/04/121709.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>行万里\Q读万卷?/title><link>http://www.aygfsteel.com/alex/archive/2007/05/29/120644.html</link><dc:creator>Alex</dc:creator><author>Alex</author><pubDate>Tue, 29 May 2007 03:32:00 GMT</pubDate><guid>http://www.aygfsteel.com/alex/archive/2007/05/29/120644.html</guid><wfw:comment>http://www.aygfsteel.com/alex/comments/120644.html</wfw:comment><comments>http://www.aygfsteel.com/alex/archive/2007/05/29/120644.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.aygfsteel.com/alex/comments/commentRss/120644.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/alex/services/trackbacks/120644.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://www.aygfsteel.com/alex/archive/2007/05/29/120644.html'>阅读全文</a><img src ="http://www.aygfsteel.com/alex/aggbug/120644.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/alex/" target="_blank">Alex</a> 2007-05-29 11:32 <a href="http://www.aygfsteel.com/alex/archive/2007/05/29/120644.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>?lt;应用Railsq行敏捷Web开?gt;看设计过E?/title><link>http://www.aygfsteel.com/alex/archive/2007/05/24/119566.html</link><dc:creator>Alex</dc:creator><author>Alex</author><pubDate>Thu, 24 May 2007 01:52:00 GMT</pubDate><guid>http://www.aygfsteel.com/alex/archive/2007/05/24/119566.html</guid><wfw:comment>http://www.aygfsteel.com/alex/comments/119566.html</wfw:comment><comments>http://www.aygfsteel.com/alex/archive/2007/05/24/119566.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/alex/comments/commentRss/119566.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/alex/services/trackbacks/119566.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://www.aygfsteel.com/alex/archive/2007/05/24/119566.html'>阅读全文</a><img src ="http://www.aygfsteel.com/alex/aggbug/119566.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/alex/" target="_blank">Alex</a> 2007-05-24 09:52 <a href="http://www.aygfsteel.com/alex/archive/2007/05/24/119566.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zt]学习 RESThttp://www.aygfsteel.com/alex/archive/2007/01/23/95440.htmlAlexAlexTue, 23 Jan 2007 00:30:00 GMThttp://www.aygfsteel.com/alex/archive/2007/01/23/95440.htmlhttp://www.aygfsteel.com/alex/comments/95440.htmlhttp://www.aygfsteel.com/alex/archive/2007/01/23/95440.html#Feedback0http://www.aygfsteel.com/alex/comments/commentRss/95440.htmlhttp://www.aygfsteel.com/alex/services/trackbacks/95440.htmlkey words: REST webservice

转自廖宇LWeblog

REST 是由 Roy Fielding 在他的论?a >《Architectural Styles and the Design of Network-based Software Architectures?/a>中提出的一个术语?/p>

REST 是英?Representational State Transfer 的羃写,有中文翻译ؓ“具象状态传输”(参考:《SIP/IMS|络中的Representational State Transfer (REST)和数据分布?/a>Q?/p>

————————————?/p>

前面的内Ҏ(gu)较枯燥,我说说我自己的理解?/p>

但是 REST 到底是什么呢Q论文我看不懂,不过扑ֈ一更单易懂的东西Q?a >《Building Web Services the REST Way?/a>?/p>

Ҏ(gu)q篇文章Q我整理了一下我自己?REST 的理解:

REST 首先只是一U架构样式,不是一U标?/strong>。这点和 Ajax cMQ两者都是利用现有的成熟技术?/p>

?REST 的定义中Q一?Web 应用L使用固定?URI 向外部世界呈玎ͼ或者说暴露Q一个资?/strong>?/p>

URI 是英?Uniform Resource Identifier 的羃写,中文译“通用资源标志W”?/p>

“通用资源标志W”是?strong>唯一标识一个资源(xhtml 文g、图片、css 样式表)的字W串。当然了QRFC 中定义的 URI 复杂得多Q不q我们此处将 URI 惌成一个h的n份证Lp了(你不能有两个同时有效的n份证LQ一个号码也不可能同时对应两个hQ。而我们天天挂在嘴边的 URL 地址是 URI 的一U表现Ş式(个h理解Q有错请U正Q?

知道什么是 URI 后,我们来看一个实际例子:

http://www.example.com/photo/logo 指向 example.com |站Q可以视Z?Web 应用Q中cd?photoQ名字ؓ logo 的资源。我们用览器访问这?URIQ看到的可能是一?xhtml 文档Q其中用 <img src=”……?/> 来显C实际的照片?/p>

http://www.example.com/photo/logo 很容易让你想?URL 重写。事实上Q这个地址很可能会在服务器内部处理?http://www.example.com/photo.php?name=logo q样的地址。photo.php 是服务器端的一个动态脚本文ӞҎ(gu) name 参数生成 xhtml 文档q回l浏览器?/p>

现在假设我们要获取这张照片的 XML 文档。XML 文档中包含照片的文g名、文件大、拍摄日期等{信息。也是说我们要获取“同一个资源的不同表现形式的数据?/strong>。对于这个要求,我们可以很容易的用另一?URL 地址辑ֈQhttp://www.example.com/xml/logo?/p>

但是Q这p背了“URI 唯一标识一个资源?/strong>的定义。如果我们要获取同一个资源的多种表现形式Q那么就要用更多的 URLQ从而给一个资源指定了多个不同?URI?/p>

而在 REST 中,不管是获取照片的 xhtml 文档q是 XML 文档Q或者照片文件本w,都是用同一?URIQ就?http://www.example.com/photo/logo?/p>

那这是怎么办到的呢QRuby On Rails 中是通过分L HTTP Request Header 信息来分辨客L是想要取得资源的哪一U表现Ş式的数据?/p>

当我们用览器访问一个网址Ӟ览器会构造一?HTTP h。这个请求有一个头信息Q其中包括了本次h接受何种cd的数据。通常览器发送的 HTTP h头中QAccept 的值都?*/*Q也p接受服务器返回的Mcd的数据?/p>

看到q里Q聪明的家伙应该知道了。只要我们指定一个特定的 Accept 参数Q那么服务器可以通过判断该参数来军_q回什么类型的数据。所以在一个采?REST 架构的应用中Q要获取同一个资源的不同表现形式的数据,只需要用不同的 HTTP h头信息就行了?/p>

如果考虑?Web 应用增加 Web ServicesQ这U技术的价值就体现出来了。比如我写了一?Delphi E序Q现在只需要构造一个包?Accept: text/xml ?HTTP h_然后请求发送到 http://www.example.com/photo/logo 可以了。返回的l果是一?XML 文档Q而不?xhtml 文档?/p>

因ؓ我们?HTTP h头信息有不同的状态,从而可以获得不同的数据Q所以叫做“具象状态传输?:)

————————————?/p>

除了上面的用法,REST q有q一步的扩展?/p>

我们?Web 应用中处理来自客L的请求时Q通常只考虑 GET ?POST q两U?HTTP hҎ(gu)。实际上QHTTP q有 HEAD、PUT、DELETE {请求方法。而在 REST 架构中,用不同的 HTTP hҎ(gu)来处理对资源?CRUDQ创建、读取、更新和删除Q操作:

  • POST: 创徏
  • GET: d
  • PUT: 更新
  • DELETE: 删除

l过q样的一番扩展,我们对一个资源的 CRUD 操作可以通过同一?URI 完成了:

http://www.example.com/photo/logoQ读取)
仍然保持?[GET] http://www.example.com/photo/logo

http://www.example.com/photo/logo/createQ创建)
改ؓ [POST] http://www.example.com/photo/logo

http://www.example.com/photo/logo/updateQ更斎ͼ
改ؓ [PUT] http://www.example.com/photo/logo

http://www.example.com/photo/logo/deleteQ删除)
改ؓ [DELETE] http://www.example.com/photo/logo

从而进一步规范了资源标识的用?/p>

通过 REST 架构QWeb 应用E序可以用一致的接口QURIQ暴露资源给外部世界Qƈ提供对资源的操作服务。这对于以资源ؓ中心?Web 应用来说非常重要。例如照片共享网站、用L区等?/p>

————————————?/p>

Ruby On Rails 1.2 版对 REST 有很好的支持Q但要在 PHP 中应?REST q需要解决不问题:

  • 如何在服务端判断 PUT、DELETE hҎ(gu)Q?
  • 如何获取?PUT、DELETE hҎ(gu)中传递的数据Q?
  • 如何获取 HTTP h头信息中?Accept 参数|
  • 如何在浏览器端发?PUT ?DELETE h?

不过我仔l看?PHP 文档Q我觉得上面几个问题都是可以解决的?/p>

服务端综合?$_SERVER[’HTTP_ACCEPT’]?_SERVER[’REQUEST_URI’]?_SERVER[’REQUEST_METHOD’]?_SERVER[’QUERY_STRING’] q些变量应该可以搞定前面三个问题。而第四个问题则可以用 JavaScript ?XMLHttpRequest 对象来实现?/p>

不过我想 REST 的真正h(hun)值在?Web ServicesQ而不是通过览器操作的应用E序?/p>

————————————?/p>

参考:



Alex 2007-01-23 08:30 发表评论
]]>
վ֩ģ壺 ʯȪ| «| ¬| | ɽ| ƽ| | | | | ԭ| ʡ| | | | պ| | | | | | ͭ| ƽ| | | β| | ޶| ػ| | ƽԭ| | | ͷ| | | | | Ϫ| | |