Web Service: REST  原則與實作分享 簡報者:許登傑、林宗茂 更新日期: 2008-09-01
大綱 REST 打哪來 ? REST for rest  ♨ Client  操作範例 Curl  指令運用 Server  開發思維 實作分享 (Resource Template) 現行限制 & 框架支援 (Framework) 參考文獻 & 相關資源
REST 打哪來 ?  # 1 SOA   ≈  LEGO Web Service   Implementation RPC 、 SOAP 、 REST Re presentational  S tate  T ransfer 2000, doctoral thesis of Roy Fielding Style  of software architecture for  distributed hypermedia systems R esource  O riented  A rchitecture W orld  W ide  W eb
REST 打哪來 ?  # 2 Client (Server) Request:   GET https ://.../customers/1/orders Response:  Content-type:   XML https://.../orders/00131 https://.../orders/00832 https://.../orders/00759 Server db3n2u.sinica.edu.tw/~textdb/ap … /orders/ { id } POST /   GET / PUT / DELETE /customers/ { id } POST /   GET / PUT / DELETE /customers/ { id } /orders POST /   GET  / PUT / DELETE
REST 打哪來 ?  # 3 ROA : Four Concepts Resource resource  Name Representation  of a resource * code on demand Link to  a related resource ROA : Four Properties Addressability Uniform interface  * (# 4) well-defined operations, CRUD Statelessness Connectedness
REST 打哪來 ?  # 4 Verbs of HTTP Safe : no changes to any data on the server Idempotent : repeat without changing resource DELETE GET ○ X Delete ○ X Update create PUT ○ ○ Read X X Create update, delete POST Idempotent Safe CRUD Method
REST for rest  ♨  - Client  操作範例 REST-like on the web End user:   www.flickr.com AP / Server:   殷周金文資料庫 : GIS 座標 how to be a Client curl  /  libcurl  ( PHP/CURL )  * ex. db3x Other development… HTTP/FTP client libraries  * open source C  * libcurl  c interface  /  bindings JAVA  * Yahoo! Developer Network .NET (C#)  * Yahoo! Developer Network
REST for rest  ♨  - curl  指令操作範例 GET curl -G -d <data> -d <data> (URL) POST curl --request POST -d <data> -d <data> (URL) PUT curl --request PUT -d <data> -d <data> (URL) DELETE curl --request DELETE -d <data> -d <data> (URL) *<data>  :  variable=value
REST for rest  ♨  - curl  指令其他常用參數 curl –help :  線上求助 -u  <login:passwd> : Set user and password --silent :  不顯示 curl 回應訊息 --data-urlencode  <name=data/name@filename> : HTTP GET data url encoded  -1/--tlsv1 : Use TLSv1 (SSL) -2/--sslv2 : Use SSLv2 (SSL) -3/--sslv3 : Use SSLv3 (SSL) -k : SSL without certification
REST for rest  ♨  -  在 C 語言中執行  curl 若開發環境無法安裝  libcurl , 則直接執行  curl  指令代替 system(cmd); 指令執行成功回傳  0 、失敗回傳  -1 system(cmd > out.txt); 需取得回傳資料,可輸出為文件檔
REST for rest  ♨  - Server  開發思維 Uniform Interface
實作分享  # 1: DORE combined (Resource Template) header('Content-Type: application/vnd.google-earth.kml+xml; charset=utf-8'); echo $loader->run(); REQUEST https:// login:passwd@db1n... _login, _passwd RESPONSE $loader = new Loader(‘gismap'); $_roleList = '*'; $_webService0 = 2; require_once('../../dore/lib0.php'); $_sess->close(); <<interface>> REST restPost() restGet() restPut() restDelete() <<resource>> gismap err() usage() chkArgs() restPost() restGet() restPut() restDelete() <<handler>> Loader err() run() auth()
實作分享  # 2 (Resource Template) Key issues Authentication, Authorization HTTP basic authentication DORE Variable / Data security  * chkArgs() Verbs reacting criteria Error handler  * Yahoo! Developer Network 1  /  2
現行限制 & 框架支援 No Framework, No PUT / DELETE PHP-based Framework Zend IBM Project Zero  * WebSphere sMash WSDL 2.0  support for all HTTP verbs Java, .Net SOAP frameworks Spring, Apache CXF, Apache Axis2
參考文獻 & 相關資源 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 / http://curl.haxx.se/ http:// developer.yahoo.com/php /

REST Web Sebvice

  • 1.
    Web Service: REST 原則與實作分享 簡報者:許登傑、林宗茂 更新日期: 2008-09-01
  • 2.
    大綱 REST 打哪來? REST for rest ♨ Client 操作範例 Curl 指令運用 Server 開發思維 實作分享 (Resource Template) 現行限制 & 框架支援 (Framework) 參考文獻 & 相關資源
  • 3.
    REST 打哪來 ? # 1 SOA ≈ LEGO Web Service Implementation RPC 、 SOAP 、 REST Re presentational S tate T ransfer 2000, doctoral thesis of Roy Fielding Style of software architecture for distributed hypermedia systems R esource O riented A rchitecture W orld W ide W eb
  • 4.
    REST 打哪來 ? # 2 Client (Server) Request: GET https ://.../customers/1/orders Response: Content-type: XML https://.../orders/00131 https://.../orders/00832 https://.../orders/00759 Server db3n2u.sinica.edu.tw/~textdb/ap … /orders/ { id } POST / GET / PUT / DELETE /customers/ { id } POST / GET / PUT / DELETE /customers/ { id } /orders POST / GET / PUT / DELETE
  • 5.
    REST 打哪來 ? # 3 ROA : Four Concepts Resource resource Name Representation of a resource * code on demand Link to a related resource ROA : Four Properties Addressability Uniform interface * (# 4) well-defined operations, CRUD Statelessness Connectedness
  • 6.
    REST 打哪來 ? # 4 Verbs of HTTP Safe : no changes to any data on the server Idempotent : repeat without changing resource DELETE GET ○ X Delete ○ X Update create PUT ○ ○ Read X X Create update, delete POST Idempotent Safe CRUD Method
  • 7.
    REST for rest ♨ - Client 操作範例 REST-like on the web End user: www.flickr.com AP / Server: 殷周金文資料庫 : GIS 座標 how to be a Client curl / libcurl ( PHP/CURL ) * ex. db3x Other development… HTTP/FTP client libraries * open source C * libcurl c interface / bindings JAVA * Yahoo! Developer Network .NET (C#) * Yahoo! Developer Network
  • 8.
    REST for rest ♨ - curl 指令操作範例 GET curl -G -d <data> -d <data> (URL) POST curl --request POST -d <data> -d <data> (URL) PUT curl --request PUT -d <data> -d <data> (URL) DELETE curl --request DELETE -d <data> -d <data> (URL) *<data> : variable=value
  • 9.
    REST for rest ♨ - curl 指令其他常用參數 curl –help : 線上求助 -u <login:passwd> : Set user and password --silent : 不顯示 curl 回應訊息 --data-urlencode <name=data/name@filename> : HTTP GET data url encoded -1/--tlsv1 : Use TLSv1 (SSL) -2/--sslv2 : Use SSLv2 (SSL) -3/--sslv3 : Use SSLv3 (SSL) -k : SSL without certification
  • 10.
    REST for rest ♨ - 在 C 語言中執行 curl 若開發環境無法安裝 libcurl , 則直接執行 curl 指令代替 system(cmd); 指令執行成功回傳 0 、失敗回傳 -1 system(cmd > out.txt); 需取得回傳資料,可輸出為文件檔
  • 11.
    REST for rest ♨ - Server 開發思維 Uniform Interface
  • 12.
    實作分享 #1: DORE combined (Resource Template) header('Content-Type: application/vnd.google-earth.kml+xml; charset=utf-8'); echo $loader->run(); REQUEST https:// login:passwd@db1n... _login, _passwd RESPONSE $loader = new Loader(‘gismap'); $_roleList = '*'; $_webService0 = 2; require_once('../../dore/lib0.php'); $_sess->close(); <<interface>> REST restPost() restGet() restPut() restDelete() <<resource>> gismap err() usage() chkArgs() restPost() restGet() restPut() restDelete() <<handler>> Loader err() run() auth()
  • 13.
    實作分享 #2 (Resource Template) Key issues Authentication, Authorization HTTP basic authentication DORE Variable / Data security * chkArgs() Verbs reacting criteria Error handler * Yahoo! Developer Network 1 / 2
  • 14.
    現行限制 & 框架支援No Framework, No PUT / DELETE PHP-based Framework Zend IBM Project Zero * WebSphere sMash WSDL 2.0 support for all HTTP verbs Java, .Net SOAP frameworks Spring, Apache CXF, Apache Axis2
  • 15.
    參考文獻 & 相關資源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 / http://curl.haxx.se/ http:// developer.yahoo.com/php /

Editor's Notes

  • #4 Service-oriented architecture , a computer systems architectural style for creating and using business processes, packaged as services . http://en.wikipedia.org/wiki/Service-oriented_architecture IT 資源 &gt;&gt; 服務 ( 設計層次高於 function, component, procedure) Web Service : Web APIs that can be accessed over a network, 可實現 xOA 的技術集合 http://en.wikipedia.org/wiki/Web_service RPC : distributed function (method) call interface. Mapping directly language-specific functions. SOAP : message, rather than an operation. REST : interacting with stateful resources. Roy Fielding , one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification. Style : (guideline) network architecture principles, outline how resources are defined and addressed. (Simple interface, Domain-specific data, Non-additional info) distributed hypermedia systems : such as the World Wide Web. ROA : 2007 book, RESTful Web Services. Every resource is a service. (Four concepts, four properties)
  • #5 https: TCP/IP model &gt; Application Layer &gt; HTTP
  • #6 Four concepts Resource : could be a physical resource, or even a person. Can be described by a representation. Name : URI for use in hypermedia links. Representation : HTTP header Content-type, describe the resource (XML / HTML / JSON / link). Link to : response to other resources. Four properties Addressability : set as URIs and allows clients to manipulate their state. Uniform interface : verbs reacting criteria (GET / PUT / POST / DELETE). Statelessness : server only keeps resource state; client keeps application state. Connectedness : have a set of links (URIs). REST principle &gt; protocol : client-server, stateless, cacheable, layered (intermediaries)
  • #15 WSDL: an XML -based language that provides a model for describing Web services .