REST Web Sebvice

1,286 views
1,142 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,286
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • 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 資源 >> 服務 ( 設計層次高於 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)
  • https: TCP/IP model > Application Layer > HTTP
  • 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 > protocol : client-server, stateless, cacheable, layered (intermediaries)
  • WSDL: an XML -based language that provides a model for describing Web services .
  • REST Web Sebvice

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

    ×