More Related Content More from Yohei Yamamoto(7) REST 入門1. REST 入門 株式会社リコー ソフトウェア研究開発本部 山本陽平 2005 年 11 月 24 日 第八回 XML 開発者の日 23. エントリ一覧の取得 HTTP GET GET /entrylist HTTP/1.1 Host: example.com X-WSSE: UsernameToken… HTTP/1.1 200 OK Content-Type: application/atom+xml <feed> <title>yohei-y:weblog</title> <entry> <link href=“/entry/0” /> </entry> <entry> <link href=“/entry/1” /> </entry> … </feed> 各エントリへのハイパーリンク リンクを辿る (href の URI を HTTP GET する ) と… 24. エントリの取得 HTTP GET GET /entry/0 HTTP/1.1 Host: example.com X-WSSE: UsernameToken… HTTP/1.1 200 OK Content-Type: application/atom+xml <entry> <title>REST 入門 </title> <published >2005-11-24T23:01:01</published> <content> <p>REST は … </p> </content> </entry> 25. エントリの更新 HTTP PUT HTTP/1.1 204 No Content PUT /entry/0 HTTP/1.1 Host: example.com Content-Type: application/atom+xml X-WSSE: UsernameToken… <entry> <title>REST 入門 </title> <content> <p>REST とは … </p> </content> </entry> 26. エントリの削除 HTTP DELETE HTTP/1.1 204 No Content DELETE /entry/0 HTTP/1.1 Host: example.com X-WSSE: UsernameToken… 27. エントリの新規作成 HTTP POST HTTP/1.1 201 Created Location: http://example.com/entry/5 POST /entrylsit HTTP/1.1 Host: example.com Content-Type: application/atom+xml X-WSSE: UsernameToken… <entry> <title>REST 入門 </title> <content> <p>REST とは … </p> </content> </entry> 新規作成されたリソースの URI 28. SOAP の場合 (クライアント側プログラム) // サービスエンドポイントの初期化 BlogService bs = new BlogService(“ http://example.com/servlet/blogservice” ); // セッション開始 String sid = bs.startSession( “yohei” , “ abc123” ); // エントリ一覧の取得 Entry[] list = bs.getEntryList(sid); String eid = list[0].getEntryId(); // 先頭エントリの取得 Entry item = bs.getEntry(sid, eid); // エントリの更新 Item.setContent(“ REST とは…” ); bs.putEntry(sid, eid, item); // エントリの削除 bs.deleteEntry(sid, eid); // エントリの追加 bs.postEntry(sid, item); 29. SOAP の場合 startSession POST /servlet/blogservice HTTP/1.1 Host: example.com Content-Type: application/soap+xml <s:Envelope> <s:Body> <m: startSession > <username>yohei</username> <passwd>hogehoge</passwd> </m: startSession > </s:Body> </s:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml <s:Envelope> <s:Body> <m:startSessionResponse> <sid> 123 </sid> </m:startSessionResponse> </s:Body> </s:Envelope> セッション ID 30. SOAP の場合 getEntryList POST /servlet/blogservice HTTP/1.1 Host: example.com Content-Type: application/soap+xml <s:Envelope> <s:Body> <m: getEntryList > <sid>123</sid> </m: getEntryList > </s:Body> </s:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml <s:Envelope> <s:Body> <m:getEntryListResponse> <entryList> <entry><eid> 1 </eid>…<entry> <entry><eid> 2 </eid>…</entry> </entryList> </m:getEntryListResponse> </s:Body> </s:Envelope> エントリ ID セッション ID 31. SOAP の場合 getEntry POST /servlet/blogservice HTTP/1.1 Host: example.com Content-Type: application/soap+xml <s:Envelope> <s:Body> <m: getEntry > <sid>123</sid> <eid> 1 </eid> </m: getEntry > </s:Body> </s:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml <s:Envelope> <s:Body> <m:getEntryResponse> <entry> <title>REST 入門 </entry> <content>…</content> </entryList> </m:getEntryResponse> </s:Body> </s:Envelope> エントリ ID 32. SOAP の場合 putEntry POST /servlet/blogservice HTTP/1.1 Host: example.com Content-Type: application/soap+xml <s:Envelope> <s:Body> <m: putEntry > <sid>123</sid> <eid>1</eid> <entry> <title>REST 入門 </title> <content>…</content> </entry> </m: putEntry > </s:Body> </s:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml <s:Envelope> <s:Body> <m:putEntryResponse /> </s:Body> </s:Envelope> 33. SOAP の場合 deleteEntry POST /servlet/blogservice HTTP/1.1 Host: example.com Content-Type: application/soap+xml <s:Envelope> <s:Body> <m: deleteEntry > <sid>123</sid> <eid>1</eid> </m: deleteEntry > </s:Body> </s:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml <s:Envelope> <s:Body> <m:deleteEntryResponse /> </s:Body> </s:Envelope> 34. SOAP の場合 postEntry POST /servlet/blogservice HTTP/1.1 Host: example.com Content-Type: application/soap+xml <s:Envelope> <s:Body> <m: postEntry > <sid>123</sid> <entry> <title>REST 入門 </title> <content>…</content> </entry> </m: postEntry > </s:Body> </s:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml <s:Envelope> <s:Body> <m:postEntryResponse> <eid>5</eid> </m:postEntryResponse> </s:Body> </s:Envelope> 35. REST (APP) と SOAP REST URI 1 URI 2 URI 3 entrylist entry entry HTTP GET HTTP GET HTTP PUT URI 1 End point HTTP POST HTTP POST HTTP POST getEntryList() getEntry(id) putEntry(entry) SOAP 44. ネットワークシステムのアーキテクチャスタイル CS CSS C$SS LC$SS LCODC$SS REST Data-flow Style Replication Style Peer-to-Peer Style Hierarchical Style Mobile Code Style PF UPF RR $ LS LCS RS RDA VM REV COD MA EBI C2 DO BDO U