• Like
  • Save

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Intro to REST

  • 1,324 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,324
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Roy Fielding , HTTP 协议制定者之一

Transcript

  • 1. REST 简介 高 磊 www.lostleon.com
  • 2. 大纲
    • REST 简介
    • REST Server 开发思想
    • 现有框架支持 (Framework)
    • 参考文献 & 相关资源
  • 3. REST 简介 # 1
    • Web Service
      • 根据 W3C 的定义, Web service 应当是一个软件系统,用以支持网络间不同机器的互动操作。
      • Web Service 三种最普遍的调用手段
        • 远程过程调用( RPC ): Web Service 提供一个分布式函数或方法接 口供用户调用
        • 面向服务架构( SOA ): 通讯由消息驱动,而不再是某个动作(方法调用)
        • 表象化状态迁移 ( REST ): Web Service 类似于 HTTP 或其他类似协议,它们把接口限定在一组广为人知的标准动作中(比如 HTTP 的 GET 、 PUT 、 DELETE )以供调用
  • 4.
    • Re presentational S tate T ransfer
      • 表象化状态迁移
      • Roy Fielding 博士在 2000 年他的博士论文中提出来的一种软件架构风格
    • REST 宗旨
      • REST 从 资源 的角度来观察整个网络,分布在各处的资源由 URI 确定,而客户端的应用通过 URI 来获取资源的表形。获得这些表形致使这些应用程序转变了其状态。
      • 随着不断获取资源的表形,客户端应用不断地在转变着其状态,所谓表形化的状态转变( Representational State Transfer )
    REST 简介 # 2
  • 5. REST 简介 # 3 Client (Server) Request: GET http ://.../customers/1/orders Response: Content-type: XML /JSON http ://.../orders/00131 http://.../orders/00832 http://.../orders/00759
    • 以产品商店为例
    • 客户端请求列出 id 为 1 的用户的所有订单
    Server vps.mobroad.com /ap p … /orders/ { id } POST / GET / PUT / DELETE /customers/ { id } POST / GET / PUT / DELETE /customers/ { id } /orders POST / GET / PUT / DELETE
  • 6. REST 简介 # 4 Uniform Interface
  • 7. REST 简介 # 5
    • HTTP 交互
      • CRUD : Create, Retrieve, Update, Delete
      • Safe : 安全方法,是否改变服务器端的数据
      • Idempotent : 幂等方法,若干次串行请求是否与一次请求产生结果相同
    X X ○ X Safe Method CRUD Idempotent POST Create update, delete X GET Retrieve ○ PUT Update create ○ DELETE Delete ○
  • 8.
      • 获取所有产品列表
      • Request GET http://www.store.com/products
      • Response
      • <store>
      • <product>
      • <id>1</id>
      • <name>iPhone4</name>
      • </product>
      • <product>
      • <id>2</id>
      • <name>Mac Book Pro</name>
      • </product>
      • </store>
      • 获取某单一产品
      • Request GET http://www.store.com/product/2
      • Response
      • <product>
      • <id>2</id>
      • <name>Mac Book Pro</name>
      • <price>$900</price>
      • <popularity>100%</popularity>
      • </product>
    REST Client 开发思想 # 1
      • 添加一个新产品
      • Request POST http://www.store.com/products
      • <product>
      • <name>iPad</name>
      • <price>$600</price>
      • <popularity>90%</popularity>
      • </product>
      • Response
      • http://www.store.com/product/3
      • 更新某个指定 id 的产品
      • Request PUT http://www.store.com/product/1
      • <product>
      • <price>$300</price>
      • </product>
      • Response
      • (only header)
      • 删除某单一产品
      • Request DELETE http://www.store.com/product/2
      • Response
      • (only header)
  • 9. REST Server 开发思想 # 1
  • 10. 现有框架支持 (Framework)
    • No Framework, No PUT / DELETE
    • PHP-based Framework
      • Zend
    • Ruby on Rails
  • 11. 参考文献 & 相关资源
    • http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
    • “ RESTful Web Services”; Leonard Richardson, Sam Ruby; (First Edition) May 2007
    • http://www.wikipedia.org/