Download - REST Web Sebvice
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 Representational State Transfer
2000, doctoral thesis of Roy FieldingStyle of software architecture
for distributed hypermedia systemsResource Oriented Architecture
World Wide Web
REST 打哪來 ? # 2
Client
(Server)
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
Request: GET
https://.../customers/1/orders
Response:
Content-type: XML
https://.../orders/00131
https://.../orders/00832
https://.../orders/00759
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
Method CRUD Safe Idempotent
POST Createupdate, delete X X
GET Read ○ ○
PUT Updatecreate X ○
DELETE Delete X ○
REST for rest ♨ - Client 操作範例 REST-like on the web
End user: www.flickr.com AP / Server: 殷周金文資料庫: GIS座標
how to be a Clientcurl / 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 certificatio
n
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)
<<interface>>REST
restPost()restGet()restPut()restDelete()
<<resource>>gismap
err()usage()chkArgs()restPost()restGet()restPut()restDelete()
<<handler>>Loader
err()run()auth()
header('Content-Type: application/vnd.google-earth.kml+xml; charset=utf-8');
echo $loader->run();
REQUEST1. https:// login:[email protected]. _login, _passwd
RESPONSE
$loader = new Loader(‘gismap');
$_roleList = '*';$_webService0 = 2;require_once('../../dore/lib0.php');
$_sess->close();
實作分享 # 2
(Resource Template)
Key issuesAuthentication, Authorization
• HTTP basic authentication• DORE
Variable / Data security *chkArgs()
Verbs reacting criteriaError handler *Yahoo! Developer Network 1 / 2
現行限制 & 框架支援
No Framework, No PUT / DELETE PHP-based Framework
ZendIBM Project Zero *WebSphere sMash
WSDL 2.0 support for all HTTP verbsJava, .Net SOAP frameworksSpring, 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/