REST Best Practices
YAMAMOTO Yohei
http://yohei-y.blogspot.com
REST ãããã
- REST ã¯ã¢ã¼ããã¯ãã£ã¹ã¿ã¤ã«
- Web ã·ã¹ãã ã®è¨è¨ã®æéã«ã§ãã
- ç¹ã« HTTP 㨠URI ãæ£ãã使ãã®ãéè¦
- å¯ç¨æ§ã¨ç¸äºéç¨æ§
REST ãã©ã使ãã
- è¨è¨ã®åèã¨ãã¦
- Web ã·ã¹ãã ã®ç解ä¿é²ã«
- ããã£ãã©ãªã®å
±æã¨ãã¦
- ãããã¹ãã¼ãã¬ã¹?ã
- ãçµ±ä¸ã¤ã³ã¿ã¼ãã§ã¼ã¹ä½¿ãããã
Web ã·ã¹ãã
- Web ã使ã£ãã·ã¹ãã
- Web ã¢ããªã±ã¼ã·ã§ã³(UI)
- Web ãµã¼ãã¹
- 両è
ãåããæå³ã¯ãã¾ããªã
- ãããåããã«æ¸ã¾ãã»ãããã
- microformats
- 人ã«ãããã°ã©ã ã«ãããããã XHTML
- ãããåããã«æ¸ã¾ãã»ãããã
Web ã·ã¹ãã ã®è¨è¨
- "ã¦ã§ãæ¦ç¥ã¨ãã¦ã®ãã¦ã¼ã¶ã¼ã¨ã¯ã¹ããªã¨ã³ã¹ã"ãã
- Web ã¯ãã¨ãã¨ãã¤ãã¼ããã¹ãã·ã¹ãã ã ã£ã
- è¿å¹´ã¯ UI ã¨ãã¦ã® Web ã®æè¡é©æ°ãéä¸ç
- Ajax å¨è¾º
ãã¤ãã¼ã¡ãã£ã¢ã·ã¹ãã ã®è¨è¨
- æ¬è³ªçã«ã¯ URI ã®è¨è¨
- Cool URI éè¦
- ãã¬ã¼ã ã¯ã¼ã¯éè¦
- è¯ããã¬ã¼ã ã¯ã¼ã¯ã使ãã¨è¯ã URI ãä½ãããã
- å¤ã/æªããã¬ã¼ã ã¯ã¼ã¯ã®ãå©ç¨ã¯è¨ç»çã«
- ãã¼ã¿éè¦
- open data
- ãã¼ã¿ã¸ã®ã¢ã¯ã»ã¹æ段ãç¨æãã
ã©ãããã°ã¯ã¼ã«ã«ãªãã®ã?
- 1 å¤ããªã
- 2 å¤ãã«ãããã
- 3 å¤ãã£ãããªãã¤ã¬ã¯ã
- 4 ããããã
å¤ããã«ãã URI ã®è¨è¨ã®ãã³ã
- å®è£
ã«ä¾åããªã
- *.pl ã¨ã
- ãªã½ã¼ã¹ã¯åè©
- URI ã« action (get/set ãªã©)ã¯å ¥ããªã
- ã»ãã·ã§ã³IDãå ¥ããªã
- ãªãã¹ãã¤ãããã®ãã¬ã¼ã ã¯ã¼ã¯ã使ã
- Web ã¢ããªã¨Web API 㧠URI ãåããªã
- /xmlrpc ã¨ãã¯ãããªã
REST çã«ã¯
- URI ã¯ã¯ã©ã¤ã¢ã³ãã«ä¸éæ
- ã¯ã©ã¤ã¢ã³ãã URI ãããã£ããæ¨æ¸¬ãããããªãã®ã¯ãã¡(å¯çµå)
- ãªã³ã¯ããã©ã
- Form ãã query ãæãã
- URI template
- opensearch ã® {searchTerms}
- query params 以å¤ããã³ãã¬ã¼ãå
- http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-00.txt
- ã¾ã ã©ããªããããããªã
1 URI ã¾ã¨ã
- å¤ããªãã®ãéè¦
- å¤ãã«ãããã工夫
- tkawa ããã® map.resources 解説ã«æå¾
Web ã¢ããªã¨ Web ãµã¼ãã¹ãåãã¦èããªã
- æªãä¾ã¨è¯ãä¾
- ã» ã¯ã¦ãªããã¯ãã¼ã¯ä»¶æ°åå¾ API
- æ¿ï½¢ï½« ããã¯ãã¼ã¯æ°ãç»åã§åå¾ãã API
件æ°åå¾API ãªã¯ã¨ã¹ã
POST /xmlrpc HTTP/1.1 Host: b.hatena.ne.jp Content-Type: text/xml <methodCall> <methodName>bookmark.getCount</methodName> <params> <param> <value><string>http://d.hatena.ne.jp/</string></value> </param> <param> <value><string>http://b.hatena.ne.jp/</string></value> </param> <param> <value><string>http://www.hatena.ne.jp/</string></value> </param> </params> </methodCall>
件æ°åå¾API ã¬ã¹ãã³ã¹
HTTP/1.1 200 OK Content-Type: text/xml Content-Encoding: gzip <?xml version="1.0" encoding="us-ascii"?> <methodResponse> <params> <param> <value> <struct> <member> <name>http://www.hatena.ne.jp/</name> <value><int>157</int></value> </member> <member> <name>http://b.hatena.ne.jp/</name> <value><int>198</int></value> </member> <member> <name>http://d.hatena.ne.jp/</name> <value><int>35</int></value> </member> </struct> </value> </param> </params> </methodResponse>
REST çã«ã©ãããã
- query document ã POST
- 201 ã¬ã¹ãã³ã¹ã¨ Location ããã
æ¹åå¾ãªã¯ã¨ã¹ã
POST /atom/exist HTTP/1.1 Host: b.hatena.ne.jp Content-Type: application/xml <uri-list> <uri>http://d.hatena.ne.jp/naoya/20051212</uri> <uri>http://yohei-y.blogspot.com</uri> </uri-list>
POST /atom/exist HTTP/1.1 Host: b.hatena.ne.jp Content-Type: application/x-www-form-urlencoded uri0=http://d.hatena.ne.jp/naoya/20051212&uri1=http://yohei-y.blogspot.com
æ¹åå¾ã¬ã¹ãã³ã¹
HTTP/1.1 201 Created Content-Type: application/atom+xml Location: http://b.hatena.ne.jp/atom/exist/1234567890abcdefg <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>ã¯ã¦ãªããã¯ãã¼ã¯æ¤ç´¢çµæ</title> <link rel="self" type="application/atom+xml" href="http://b.hatena.ne.jp/atom/exist/1234567890abcdefg"/> <updated>2003-12-13T18:30:02Z</updated> <author><name>Hatena</name></author> <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> <entry> <title>ãªããã®ã¯ã¦ãªãã¤ã¢ãªã¼</title> <link href="http://d.hatena.ne.jp/naoya/20051212"/> <link rel="alternate" href="http://b.hatena.ne.jp/entry/http://d.hatena.ne.jp/naoya/20051212"/> <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> <updated>2005-12-13T18:30:02Z</updated> <summary>5</summary> <content type="xhtml"> <!-- ãªã³ã¯ããã¼ã¯ã¼ããã¿ã°ãªããããã®ã¾ã¾å ¥ãã --> </content> </entry> <entry> <title>yohei-y:weblog</title> <link href="http://yohei-y.blogspot.com"/> <link rel="alternate" href="http://b.hatena.ne.jp/entry/http://yohei-y.blogspot.com"/> <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> <updated>2005-12-10T10:34:02Z</updated> <summary>4</summary> <content type="xhtml"> <!-- ãªã³ã¯ããã¼ã¯ã¼ããã¿ã°ãªããããã®ã¾ã¾å ¥ãã --> </content> </entry> </feed>
ã¬ã¹ãã³ã¹ã¯ JSON ã§ã JSONP ã§ã
HTTP/1.1 201 Created Content-Type: application/json Location: http://b.hatena.ne.jp/atom/exist/1234567890abcdefg { "http://d.hatena.ne.jp/naoya/20051212": 5, "http://yohei-y.blogspot.com" : 4 }
è¯ãä¾ ããã¯ãã¼ã¯æ°ãç»åã§åå¾ãã API
ãªã¯ã¨ã¹ã(ããã¯ãã¼ã¯æ°ãªã½ã¼ã¹)
GET /entry/image/http://d.hatena.ne.jp HTTP/1.1 Host: b.hatena.ne.jp
ã¬ã¹ãã³ã¹
HTTP/1.1 200 OK Content-Type: image/png binary data
æ¬å½ã®åãã¯
HTTP/1.1 302 Moved Temporarily Location: http://b.hatena.ne.jp/images/users/normal/00036.png
GET /users/normal/00036.png Host: b.hatena.ne.jp
HTTP/1.1 200 OK Content-Type: image/png Etag: "d7a218-1f9-f35b8700" binary data
ç»åãGETããã¨ãã£ãã·ã¥ã«ããã
GET /users/normal/00036.png Host: b.hatena.ne.jp If-Modified-Since: Fri, 07 Jul 2006 08:54:03 GMT If-None-Match: "d7a218-1f9-f35b8700"
HTTP/1.1 304 Not Modified Content-Type: image/png Etag: "d7a218-1f9-f35b8700"
ãªã«ãè¯ã?
- ãã£ãã·ã¥ãæå¹å©ç¨
- ã¬ã¹ãã³ã¹ã³ã¼ããæ£ããå©ç¨
- HTML ãã img/@src ã§ãªã³ã¯å¯è½!
- Web ã¢ããªã¨ Web ãµã¼ãã¹ãåãã¦èãã¦ããªã
- ç´°ããããã³ã
- 302 㯠Found ãããªãã®? (RFC2616)
- Moved Temporarily 㯠RFC 2068
- Expires ãæå®ããæ¹ããããã
- 302 㯠Found ãããªãã®? (RFC2616)
ã¯ã¦ãªããã¯ãã¼ã¯APIã®åæ
- 件æ°åå¾ã®æå (æ¨æ¸¬)
- åãã«ã¡ã½ããã³ã¼ã«çã«èãã?
- ãã©ã¼ãããã§æ©ãã§ãã¾ã£ã
- ç»ååå¾ã®åå (æ¨æ¸¬)
- img è¦ç´ ããã®å©ç¨(ãªã³ã¯)ã念é ã«?
ãªã³ã¯éè¦
- ãªã³ã¯å¯è½ãªãã® == REST çã«æ£ãããªã½ã¼ã¹
Web API è¨è¨ã®ãã³ã(2)
- 2 ãã®ãªã½ã¼ã¹ã«é©ãã表ç¾ã¯ä½ã?
- XHTML/microformats
- image/*, application/*
- ç´ atom entry
- æ¡å¼µã¿ã°ã¤ã atom entry
- JSON, JSONP
- ç¬èªãã¼ã¯ã¢ãã
ãªã½ã¼ã¹è¡¨ç¾é¸æã®ææ³
- æ®å¿µãªãã決å®çãªææ³ã¯ç¥ããªã
- çµé¨+ã»ã³ã¹ããã®ãè¨ãä¸ç
- ãããã¡ã¯ããéè¦
- ãçä¼¼ãéè¦
- ã»ã³ã¹ã®è¯ã API ãçä¼¼ããã
- GData, Hatena APIs
2 Web API ã®è¨è¨
- ããã
3 æè¿ã® REST é¢ä¿ã®è©±é¡(1)
- REST æ¬
- æ¥å¹´5æ?
- ä»æ¥è©±ãããããªå 容ãããå æ¬çã«
- SOA ã¸ã®å¯¾æã¤ããªãã®ã¼ã¨ãã¦ã® ROA
æè¿ã® REST é¢ä¿ã®è©±é¡(2)
- blog ã§å¯¾è©±å½¢å¼ãã¯ãã£ã¦ã¾ã
- REST Dialogues by Duncan Cragg
- 9åã®äºå®(ç¾ç¶äºã¤)
- The S stands for Simple by Pete Lacey
- ã»ã¨ãã©è¨³ãããã ãã©æå¾ã®ä¸æã訳ããæ«æä¸orz
- REST Dialogues by Duncan Cragg
æè¿ã® REST é¢ä¿ã®è©±é¡(3)
- ã¤ã³ã¿ãã¥ã¼ at infoQ
- Tim Bray
- DHH
æè¿ã® REST é¢ä¿ã®è©±é¡(4)
- uddi public directory çµäº 2005/12
- å¤ãª REST 解説ãå¤æ°
- ã¹ã«ã¼åéè¦
- REST/WS-* 使ãããè« 2006/02
- è¯ã API ããããã
- Lucene ã¨ã
- APP ã¾ã RFC ã«ãªããªã
- ããããã
REST vs SOAP/WS-*(ROA vs SOA)
- 表é¢çãªéã
- ä»æ§ã®æ°
- 大ãã³ãã®ææ
- æ¬è³ªçãªéã
- çµ±ä¸ã¤ã³ã¿ã¼ãã§ã¼ã¹ vs åå¥ã¤ã³ã¿ã¼ãã§ã¼ã¹
- è¤é㪠MEP (Message Exchange Pattern) ãå¿ è¦ãã©ãã
ã§ããªãã£ã話
- èªè¨¼ã¾ãã
- ã¾ã ããªãã¦ãªã
- ã¨ã©ã¼ã®è©±
- torum ããããããªãã
- atom entry + hError?
ãéè´ãããã¨ããããã¾ãã
質åããã¾ãã?