RESTfulãªè¨è¨ã¨CRUDã¯ã¡ãã£ã¨ç¸æ§æªãã¨ãã話
http://www.infoq.com/jp/news/2009/08/CRUDREST
ä¸è¨URLãèªãã§èªåãªãã«ä¾é¡ãèãã¦ã¿ãã(todo:ãã¨ã§ç¶æ é·ç§»å³ã追å )
RestBucks cafe
å®å ¨ã«ãªã³ã©ã¤ã³åããã¦ãã¦WebAPIã§æ³¨æã§ããã¨ãããããã«ãã§ãæ³å®ãã¾ãã(この手の例にStarbucksを使うのはGregor Hopeさん以来の伝統らしいです)
客å´ããè¦ãã¦ã¼ã¹ã±ã¼ã¹ã¯ãããªæã
- 客ã¯ã¬ã¸ã®ãµã¼ãã¹ãå¼ã³åºãã¦ã注æãå ¥åãã¦æ¯æã
- èªå¸ã§æ³¨æç¶æ³ããã§ãã¯ãåºæ¥ä¸ãã£ã¦ãããåãã«è¡ãã
注æã¨ããã¨ã³ãã£ãã£ã¨ã[注æç·¨é] [æ¯æã] [åãåã] ã¨ãã(ã¢ããªã±ã¼ã·ã§ã³)ç¶æ ã«ãã£ã¦ä¸æã表ç¾ã§ãããã§ãã
(RESTfulã ãã©)CRUDãªè¨è¨
CURDãªè¨è¨ã§ã¯ããªã½ã¼ã¹ãURLã«ãããã³ã°ãã¾ããããã«å¯¾ãã¦CRUDããã¨ããã¤ã¡ã¼ã¸ã§ãã*1
- /order ã«POST ãã¦æ³¨æãä½æãã
- /order/1234 ã«PUT :ãããã³ã°ã追å
- /order/1234 ã«PUT:[æ¯æã]ã«ç¶æ å¤æ´
- /order/1234 ã«PUT:[åå]ã«ç¶æ å¤æ´
- /order/1234 ãGETãã¦ç¶æ³ç¢ºèª
RESTãæèããããããç¶æ
ã«é¢ããæ
å ±ãã»ãã·ã§ã³çã«ä¿æããã®ã¯é¿ãããã®ã§ã注æã¨ã³ãã£ãã£ã«æããããã¨ã«ãªãã§ããã(ã¢ããªã±ã¼ã·ã§ã³ç¶æ
ãããªã½ã¼ã¹ç¶æ
ã«ææ ¼ããã)ãããã¦POSTã«ãã£ã¦æ³¨æãªã½ã¼ã¹ãç·¨éãããã¨ã«ãã£ã¦ãç¶æ
é·ç§»ãå¼ãèµ·ããã¾ãã
ãã®ç¶æ
é·ç§»ã®ã«ã¼ã«ã¯ãã¢ããªã±ã¼ã·ã§ã³ã®ä¸ã«é ããã¦ã¾ãã
- æ¯æããããã¨åãåãå¯è½ã«ãªã
- æ¯æããããåã«ååã«ç¶æ å¤æ´ãããã¨ããã¨ã¨ã©ã¼
- æ¯æãæ¸ã¿ãã®ã«ããããã³ã°ã追å ãããã¨ããã¨ã¨ã©ã¼
- ...
ãã®ä¾ã§ã¯ãå®ã¯ã¯ã©ã¤ã¢ã³ãå´ã«ãã種ã®åæãå¼·ãã¦ãã¾ããã¤ã¾ãç¶æ é·ç§»ã®ã¢ãã«ãã¯ã©ã¤ã¢ã³ãéçºå´ãææ¡ãã¦ããå¿ è¦ãããã¾ãã
HATEOASãªè¨è¨
HATEOAS 㯠Hypermedia as the Engine of Application State ã®ç¥ã§ããç¶æ ãã·ã³ããã¤ãã¼ã¡ãã£ã¢ã§è¡¨ç¾ããã¨ããæå³ã§ããã
HATEOASãªè¨è¨ã§ã¯ãç¶æ *2ãURLã«ãããã³ã°ããã¢ã¯ã·ã§ã³ãHTTPã¡ã½ããã«ãç¶æ é·ç§»ããªã³ã¯ã«ãããã³ã°ãã¾ãã
[注æåã®ç¶æ ] /order
- POSTã§create : 次ã®ç¶æ ãè¿å´[/order/1234]
[注æ] /order/1234
- GETã§æ³¨æå 容確èª
- PUTã§æ³¨æç·¨é : 次ã®ç¶æ ãè¿å´[/order/payment/1234]
[æ¯æã] /order/payment/1234
- PUTã§æ¯æãç¢ºå® : 次ã®ç¶æ ãè¿å´[/order/receive/1234]
[åãåã] /order/receive/1234
- GETãã¦ãã§ãã¯
ç¶æ
é·ç§»ã®ã«ã¼ã«ã¯ãURLã¨ãã¤ãã¼ãªã³ã¯ãHTTPã¡ã½ããã®å¶éã«ãã£ã¦è¡¨ç¾ã§ãã¾ã
- 注æç·¨éãããå¾ã«é·ç§»ãã次ã®ç¶æ ã¯ãæ¯æãã®ç¶æ ãæå³ãããã¤ãã¼ãªã³ã¯(/order/payment/1234)ãè¿å´ãã¼ã¿ã«å«ãããã¨ã§è¡¨ç¾ã
- æ¯æãåã«åãåãã§ããªãã®ã¯ã注æä½æå¾ã«ãããªã /order/recieve/1234 ãGETããã¨404ã«ãªããã¨ã§è¡¨ç¾ã
- æ¯æãå¾ã«æ³¨æã§ããªãã®ã¯ãæ¯æãå¾ã« order/1234 ã®PUTãå¶éããããã¨ã«ãã£ã¦è¡¨ç¾ã(OPTIONSã§ç¢ºèªå¯è½)
HATEOASãªè¨è¨ã§ã¯ã¯ã©ã¤ã¢ã³ãå´ã«å¿ è¦ãªåææ¡ä»¶ãæ¸ãããã¨ãã§ãã¾ããç¶æ ãã·ã³ãå¤æ´ããã¦ããããã¯URLã¨ãã¤ãã¼ãªã³ã¯ã®å¤æ´ã§è¡¨ç¾ããã¾ãããã¨ãã°ã[注æ]ã¨[æ¯æã]ã®éã«[ã¹ãã¼ãããæ½é¸]ã¨ããç¶æ ãã§ãã¦ãã注æå¾ã«é·ç§»ããå ãå¤æ´ãããã ãã§ãã(å®å ¨ã«åæç¥èç¡ãã¨ããã®ã¯ç¡çã§ãããã)
ãã ãç¶æ
ã«å¯¾ããã¢ã¯ã·ã§ã³ã4ã¤ããå®ç¾©ã§ããªããã¨ãããããã³ã«ä¸ã®å¶ç´ãããã¾ãããã®å ´åã¯ãç¶æ
ãç´°ããåå²ããå¿
è¦ãããããã([注æ]ã¨[注æ追å ]ãåããã¨ã)*3
ããããã°ãid:t-wada ããããã£ã¦ãã RESTfulBuri ããããªæãã®å®è£
å°ãä¼¼ãæãã®è¨è¨ã ã£ãã¨æãã¾ããããã!!
ãããã¦èªã¿ãã
ãã®ä¾ããç´°ããã§ãããã æ¥æ¬èªãè¶ èªã¿ã¥ããããã
(追è¨:20100826)ãªã½ã¼ã¹ã®ç¶æ é·ç§»ãã¢ããªã±ã¼ã·ã§ã³ã®ç¶æ é·ç§»ã«å¯¾ããè¨è¿°ãæ´çããã
*1:è¨è¿°ãééã£ã¦ããã®ã§ä¿®æ£æ¸ã¿ãã³ã¡ã³ãæ¬åç §
*2:ãããã¢ããªã±ã¼ã·ã§ã³ç¶æ ãªã®ããªã½ã¼ã¹ç¶æ ãªã®ãã¯å°ãæ©ã¾ãããURLã«ãããã³ã°ãã以ä¸ãæ°¸ç¶åããªããã°ãªããªãã¨ããç¹ã§ã¯ãªã½ã¼ã¹ç¶æ
*3:ãã¯ãã®yoheiããã®çªã£è¾¼ã¿ãæ¤è¨ããå¿ è¦ãããé·ç§»èªä½ã¯ããã¤ã§ãå®ç¾©ã§ãããããã«ç¨®å¥ãä¸ãããã¨ãã§ãããã¢ã¯ã·ã§ã³ã¨é·ç§»ãåé¢ãã¦èããã»ãããã?