以äžã§ã¯ãHTTPãããã³ã«ãä»ããŠå©çšå¯èœãªãªãœãŒã¹ã®é©åãªç·šæã説æãã15ã®ãã€ã³ããèŠã€ããŸã-Webãµã€ããããã¯ãšã³ãããã³ããAPIãªã©ã ããã§ã®ãæ£ããããšã¯ããæšå¥šäºé ãšä»æ§ã«æºæ ããããšããæå³ããŸãã 以äžã®ã»ãšãã©ã¯ãIETFããã³W3Cã®å ¬åŒã®æšæºãã¬ã€ãã©ã€ã³ãããã³ãã¹ããã©ã¯ãã£ã¹ããã»ãŒæåéã翻蚳ãããŠããŸãã
ããã§ã¯æçœãªããšã¯çµ¶å¯Ÿã«ãããŸããã ããããçå£ã«ã ãã¹ãŠã® Webéçºè ã¯ãçè«çã«ã¯ããžã¥ãã¢éçºè ããã³/ãŸãã¯å€§åŠã®2幎ãŸãã¯3幎ã®é åã®ã©ããã§ãããã®15ç¹ããã¹ã¿ãŒããå¿ èŠããããŸãã
ããããå®éã«ã¯ãéåžžã«å€ãã®Webéçºè ããããã®åºæ¬ãåŠã°ãªãã£ãããšãããããŸããã ä»ã®APIãšãããã¹ãã®ããã¥ã¡ã³ããèªã¿ãŸãã ãã¹ãŠã®èªè ããã®ãªã¹ãã§èªåã«ãšã£ãŠæ°ãããã®ãèŠã€ãããšç¢ºä¿¡ããŠããŸãã
1. URLã¯ãªãœãŒã¹ïŒç¹å®ã®å ±æãšã³ãã£ãã£ïŒãèå¥ããŸãã ãã¡ã€ã«ã¯ãªãœãŒã¹ã§ãã äœããæ¢ããŠãããã³ã¯ãªãœãŒã¹ã§ãã ã¡ãœããåŒã³åºãã¯ãªãœãŒã¹ã§ã¯ãããŸããã æã®å€§ç ²ãé¿ãããå Žåã¯ããããè¡ãå¿ èŠã¯ãããŸããã
GET /?method=&to=
ãªãœãŒã¹ãsharakhalkaããååŸãããšããã¹ãŠãè«ççã«ãªããŸãã
POST //?to=
GETã§ã¯ãªãPOSTã䜿çšããçç± ä»¥äžããèªã¿ãã ããã
2. URLã¯ãã¹ããŒã ïŒãããã³ã«ïŒããã¹ãããã¹ïŒãã¹ïŒãã¯ãšãªïŒã¯ãšãªïŒãããã³ãã©ã°ã¡ã³ãã§æ§æãããŸãã ãã¹ã¯éå±€ãªãœãŒã¹ã®æŽçã«äœ¿çšãããã¯ãšãªã¯ééå±€ãªãœãŒã¹ããã³æäœãã©ã¡ãŒã¿ãŒã«äœ¿çšãããŸãã ãã©ã°ã¡ã³ãã¯ãçŽæ¥URLãæããªãåŸå±ãªãœãŒã¹ãèå¥ããŸãã
ã¹ããŒã ãã¹ããã¹ã¯ãšãªãã©ã°ã¡ã³ã ââââââ http://nyashnye-kotiki.xxx/breeds/maine-coon/?deliver_to=Moscow#photo
ãµã€ããCute catsãã«åçš®ã®ã«ã¿ãã°ãããå Žåãåç«ã¯æ£ç¢ºã«1ã€ã®åçš®ã«å±ããããããã¹ããŒãã®åœ¢åŒã§æŽçããããšã¯éåžžã«è«ççã§ãã ãã ãã1å¹ã®ç«ãè€æ°ã®éœåžã«é ä¿¡ã§ããããããéœåžNãžã®é ä¿¡ã䜿çšããããã£ã«ã¿ãŒã¯ã¯ãšãªã䜿çšããŠæŽçããå¿ èŠããããŸãã
3. HTTPåŒã³åºãã¯ãã¡ãœããïŒåè©ïŒãURLã«é©çšããããšã§æ§æãããŸãã ãã®ã¢ããªã±ãŒã·ã§ã³ã®çµæ-é©ããé©ãïŒ -åè©ã«æžãããŠããããšã ã€ãŸããGETã¯ãªãœãŒã¹ã®è¡šçŸãDELETEåé€ãªã©ãè¿ããŸãã
4.ã¡ãœããGETãHEADãOPTIONSã¯å®å šã§ãã ãããã®ã¡ãœãããåŒã³åºããŠããªãœãŒã¹ã®ç¶æ ã¯å€ãããªããšæ³å®ãããŠããŸãã ãããã£ãŠãå€ãã®ãããã¯ãŒã¯ãšãŒãžã§ã³ãïŒããšãã°ããã©ãŠã¶ãŸãã¯ã¡ãã»ã³ãžã£ãŒã®ãªã³ã¯ããªãã§ããã£ãŒãªã©ïŒã¯ããŠãŒã¶ãŒã®æ瀺çãªææãªãã«ãã®ãããªãªã³ã¯ããã©ãè³æ ŒããããšèããŠããŸãã ICHSHãæšæºã«éåããªãã§ãã ããã
5.ããã©ã«ãã§ã¯ãGETã¡ãœãããšHEADã¡ãœããã¯ãã£ãã·ã¥ãããŸãããOPTIONSãPOSTãPUTãPATCHãDELETEã¯ãã£ãã·ã¥ãããŸããã ãããã£ãŠãPOSTã¡ãœããã䜿çšããŠæã«ãžã£ã³ãããå Žåããã®ãªã¯ãšã¹ããå®è¡ãããããšã¯ïŒã»ãŒïŒç¢ºå®ã§ãã GETã¡ãœããã䜿çšããŠã·ã£ããã«ãããšãããã€ãã®äžéãããã·ããã£ãã·ã¥ããåçãçªç¶æäŸããããŒã«ã¯å®éã«ã¯çºçããŸããã
6. GETãPUTãDELETEæäœã¯å¯Ÿç§°çã§ãã PUTã¯URLã«äœãã眮ãïŒæ°ãããªãœãŒã¹ãäœæããããå€ããªãœãŒã¹ãäžæžãããŸãïŒããã®URLã«å¯ŸããGETã¯PUTã眮ãããã®ã®è¡šçŸãè¿ããDELETEã¯ãªãœãŒã¹ãåé€ããŸãã
HEADã¡ãœããã¯ãGETã¡ãœãããšæå³çã«å矩ã§ãããå¿çã®æ¬æã§ã¯ãªããããããŒïŒãªãœãŒã¹ã«é¢ããã¡ã¿æ å ±ïŒã®ã¿ãè¿ããŸãã
7.æäœãé©çšããURLããªãå Žåã¯ãPOSTã䜿çšãããŸãã ããšãã°ããŠãŒã¶ãŒããã©ãŒã©ã ã®ã¹ã¬ããã«æ°ããã¡ãã»ãŒãžãæžã蟌ãå ŽåããŠãŒã¶ãŒã¯èªåã®IDãææ¡ããŠæ¬¡ã®æäœãå®è¡ã§ããŸãã
PUT /threads/php-rulezz/messages/100500
ã¯ã©ã€ã¢ã³ããIDã®çæãèš±å¯ãããŠããªãå Žåãã¯ã©ã€ã¢ã³ãã¯éå±€ã®äžäœã¬ãã«ã®ãªãœãŒã¹ã§POSTãå®è¡ããå¿ èŠããããŸãã
POST /threads/php-rulezz/messages
ãããŠããã®ãªãœãŒã¹èªäœãæ°ããã¡ãã»ãŒãžãäœæããŸãã
誀ã£ãŠããŸãã¯ãããã¯ãŒã¯ã®åé¡ã«ããPOSTãªã¯ãšã¹ããç¹°ãè¿ããå Žåãæåã®ã¡ãã»ãŒãžãšåã2çªç®ã®ã¡ãã»ãŒãžãã¹ã¬ããã«äœæãããããšã«æ³šæããŠãã ããã å°ãªããšã100500åPUTãå®è¡ã§ããŸãããçµæã¯å€ãããŸããã ãã®ããããã£ã¯ãã¹ãçæ§ãšåŒã°ããŸãã
ããŠããã©ãŒã©ã ã®æçš¿ãäœæããŸãã çŸåšããŠãŒã¶ãŒèŠæ±ã«å¯ŸããŠéãæäœãšé«äŸ¡ãªæäœãå®è¡ããŠããå Žåãããã«å¯ŸããŠã¹ãçã®èŠæ±ãå®è¡ããããšã匷ããå§ãããŸãã ãããŠãããã¯åçã®ããã«ãªããŸãïŒ
ãã¡ãããã¹ãçPUTã®äœ¿çšã«ã¯ããèªäœã®åé¡ããããŸããç¹ã«ã競åã®è§£æ±ºæ¹æ³ã§ãã ãã£ãšããã°ã©ãã³ã°ããå¿ èŠããããŸãããçµæã¯ããä¿¡é Œæ§ãé«ãå®å šã§ãã
8. PUTã¯ãæ°ãããªãœãŒã¹ã®äœæãšå€ããªãœãŒã¹ã®æŽæ°ã®äž¡æ¹ã«äœ¿çšã§ããŸãã ãã ããPUTãæžãæãã«äœ¿çšããå Žåããšã³ã³ãŒãããããªãœãŒã¹å šäœãèŠæ±æ¬æã§éä¿¡ããããšæ³å®ãããŸãã ãªãœãŒã¹ãå€æŽããå Žåãã€ãŸã å®å šã«æžãçŽããã«å éšè¡šçŸãå€æŽããããã«ãPATCHã¡ãœãããçºæãããŸããã ãã®ã¡ãœããã¯ããã£ãã·ã¥äžå¯ã§ãå®å šã§ã¯ãªããã¹ãçã§ã¯ãããŸããã
9.ã¯ã©ã€ã¢ã³ãã次ã«äœããã¹ãããç解ã§ããããã«ãæåã«å¿çã³ãŒããå¿ èŠã§ãã 3xxã¯ããªã¯ãšã¹ããæ£åžžã«å®äºããã«ã¯ãè¿œå ã®ã¢ã¯ã·ã§ã³ãå®è¡ããå¿ èŠããããšè¿°ã¹ãŠããŸãã 4xxã¯ãã¯ã©ã€ã¢ã³ãããªã¯ãšã¹ããã³ã³ãã€ã«ãããšãã«äœãééã£ãããšãããéåžžãé Œãããšã¯åœ¹ã«ç«ããªãã®ã§ããªã¯ãšã¹ããç¹°ãè¿ãå®è¡ãããšãšã©ãŒãã¹ããŒããããšèšããŸãã 4xxã§ã¯ãã¯ã©ã€ã¢ã³ããæ£ç¢ºã«äœãééãããã«ã€ããŠã®æ å ±ãå«ããããšã匷ããå§ãããŸãã 5xxã¯ãã¯ã©ã€ã¢ã³ãããã¹ãŠãæ£ããè¡ã£ããšèšããŸã-åé¡ã¯ãµãŒããŒåŽã«ãããŸãã
éåžžãæäœãæåãããšããµãŒããŒã¯GET-200ãPUT-201 CreatedïŒãªãœãŒã¹ãäœæãããå ŽåïŒãŸãã¯200ïŒãªãœãŒã¹ãæŽæ°ãããïŒãDELETE-204ïŒæäœãæåããäœãè¿ãããªãïŒãPOST-200ãŸãã¯201ïŒ2çªç®ïŒã«å¿çããŸãããããŒïŒéåžžã¯å ŽæïŒã®å ŽåãäœæããããªãœãŒã¹ã®URLã瀺ãããŸãïŒã
10. HTTPã¹ããŒã¿ã¹ã䜿çšããå Žåãäžè¬çãªã¬ãŒããèžãŸãªãã§ãã ããã
- 401 Unauthorizedã¹ããŒã¿ã¹ã«ã¯ WWW-AuthenticateããããŒãå¿ èŠã§ãããããã¯ã©ã€ã¢ã³ããHTTPèªèšŒã§èªèšŒãããå Žåã«ã®ã¿é©çšãããŸãã ãã®ä»ã®å Žåã¯ãã¹ãŠã403 Forbiddenã䜿çšããŸãã
- 3xxã¹ããŒã¿ã¹ã¯ãªãã€ã¬ã¯ãã ãã§ã¯ãããŸããã ãããã¯ãã¯ã©ã€ã¢ã³ããè¿œå ã®ã¢ã¯ã·ã§ã³ãå®è¡ããå¿ èŠãããããšã瀺ããŠããŸããããããªããšããªã¯ãšã¹ããæåãããšèŠãªãããšãã§ããŸããã ããšãã°ãã¹ããŒã¿ã¹304 Not Modifiedã®å Žåãã¯ã©ã€ã¢ã³ãã¯ãã£ãã·ã¥ãããªãœãŒã¹ã®çŸåšã®ããŒãžã§ã³ãååŸããå¿ èŠããããŸãã
- å¥åŠãªããšã«ã404ã¹ããŒã¿ã¹ã¯ãã¯ã©ã€ã¢ã³ããç¹°ãè¿ãæš©å©ãæã€æ°å°ãªã4xxã¹ããŒã¿ã¹ã®1ã€ã§ããããã¯ãçŸåšãªãœãŒã¹ããªãããšãæå³ããŸããã衚瀺ãããå¯èœæ§ã¯ååã«ãããŸãã äžè¬ã«ã404ã¯ããµãŒããŒããšã©ãŒã®ã¡ã«ããºã ãé瀺ããããªãå Žåã«äœ¿çšãããäžç¢ºå®æ§ã¹ããŒã¿ã¹ã§ãã ã¯ã©ã€ã¢ã³ããè¿œå ã®ã¢ã¯ã·ã§ã³ãè¡ããªããšãªãœãŒã¹ã衚瀺ãããªãããšãã¯ã©ã€ã¢ã³ãã«ç€ºãã«ã¯ã410 GoneïŒãªãœãŒã¹ãåé€ãããïŒãŸãã¯äžè¬ã¹ããŒã¿ã¹400ã䜿çšããå¿ èŠããããŸãã
11.ãªãœãŒã¹ãšãã®ã¢ã¯ã·ã§ã³ããšã³ã³ãŒãããURLã®ç¹å¥ãªãµãã¯ã©ã¹ããããŸãã è±èªã®æç®ã§ã¯ããããã¯æ©èœURLãšåŒã°ããŸãã ãã®ãããªURLã®å žåçãªäŸã¯ããã¹ã¯ãŒãå埩ãªã³ã¯ãšãããããçš®é¡ã®ãªãœãŒã¹ãžã®ããããçš®é¡ã®ãç§å¯ãçŽæ¥ãªã³ã¯ã§ãã
12.ã±ãŒãããªãã£URLãæ±ãéã®äž»ãªå±éºã¯æŒæŽ©ã®å¯èœæ§ã§ããããããã®ãããªURLã誀ã£ãŠçºèŠãŸãã¯ååããå¯èœæ§ãéããå¿ èŠããããŸãã
- URLã®ç§å¯ã®éšåãçæããã«ã¯ã匷åãªã©ã³ãã æååãžã§ãã¬ãŒã¿ãŒïŒ UUID 4ãªã© ïŒã䜿çšããå¿ èŠããããŸãããã ãããã«ãŒããã©ãŒã¹ã«ãã£ãŠæ©èœURLãèŠã€ããå¯èœæ§ã¯ãããŸããã ãã¡ãããmd5ïŒãŠãŒã¶ãŒåïŒã®ãããªæ±ºå®è«çãªæ¹æ³ã§URLãçæããã¹ãã§ã¯ãªãããã®ãããªURLã¯ãªã³ã¯ççž®ãµãŒãã¹ãä»ããŠæž¡ãã¹ãã§ã¯ãããŸããã
- æ©èœURLã¯HTTPSã§ã®ã¿æ©èœããŸãã
- æ©èœURLãä»ããŠã¢ã¯ã»ã¹å¯èœãªããŒãžã¯ãããããã«ããã€ã³ããã¯ã¹äœæãã¯ã€ã«ãã«ãŒãã§ãããã¯ããå¿ èŠããããŸãã
13.èµ·ããããæå·ãæå°éã«æããããã®å¯Ÿçãè¬ããå¿ èŠããããŸãã
æ©èœURLãäœæããïŒããšãã°ãããã¥ã¡ã³ããå ±æããïŒãŠãŒã¶ãŒã¯ãéã®æäœãå®è¡ã§ããå¿ èŠããããŸãã URLãåãæ¶ã
æ©èœURLã¯æéã®çµéãšãšãã«æªåããã¯ãã§ãã ã¢ã¯ã»ã¹ãå±éºã§ããã»ã©ãURLã®å¯¿åœã¯çããªããŸãã
14.æåŸã«ããã·ãŒã¯ã¬ãããããŒãžèªäœãããµãŒãããŒãã£ãšãŒãžã§ã³ããžã®ããŒã¿æŒæŽ©ããä¿è·ããå¿ èŠããããŸãã
- ã§ããã°CSPã¬ãã«ã§ããµãŒãããŒãã£ã®ã¹ã¯ãªãããç»åã䜿çšããªãã§ãã ããã
- ãµãŒãããŒãã£ã®ãµã€ããžã®ãªã³ã¯ã䜿çšããªãã§ãã ããã å¿ èŠãªå Žåã¯ãããšãã°rel = "noreferrer"ã䜿çšããŠãªãã¡ã©ãŒãé衚瀺ã«ããå¿ èŠããããŸãã
- éåžžããªãã¡ã©ãŒããªã·ãŒãä»ããŠãªãã¡ã©ãŒã®é衚瀺ãèšå®ããããšããå§ãããŸãã
- ãŠãŒã¶ãŒãããªãã®è©è¶ãã«èŠããªãããã«ããŠãŒã¶ãŒãHistory APIãä»ããŠãã°ã€ã³ããçŽåŸã«ããã©ãŠã¶ãŒã®ã¢ãã¬ã¹ããŒã®URLãããã«å€æŽããããšããå§ãããŸã
- ãªã³ã¯ã«äœããã®ã¢ã¯ã·ã§ã³ïŒãã¹ã¯ãŒãã®å€æŽãªã©ïŒãå«ãŸããå Žåãã·ãŒã¯ã¬ããããŒãžã«ã¢ã¯ã·ã§ã³ãå®è¡ããããã«éä¿¡ããå¿ èŠã®ãããã©ãŒã ïŒãã¿ã³ãã¹ã¯ãªããïŒãããããã®ãã©ãŒã ã¯CSRFããŒã¯ã³ïŒãã©ãŠã¶ãŸãã¯é»åã¡ãŒã«ããªãã§ããã£ãŒïŒã§çœ²åããå¿ èŠããããŸãã¯ã©ã€ã¢ã³ã/ã¡ãã»ã³ãžã£ãŒã¯ãŠãŒã¶ãŒã®ãã¹ã¯ãŒããå埩ã§ããŸãïŒã
15.äžèšã®ãã¹ãŠã¯ãæšå¥šäºé ã®åœ¢åŒã§ã®ã¿æšæºã«ååšãããããã®æšå¥šäºé ãå³å¯ã«å®è£ ããããã«åŒ·å¶ããããšã¯äžå¯èœã§ãã ãã®ããªãã¢ã«ã€ããŠç§ã話ããŠããã®ã¯ãããåããŠã§ã¯ãªãããã¯ããããããã¹ãŠåãåºãããã£ãã®ã§ãã圌ãã¯äžå¿ èŠãªãã³ã»ã³ã¹ãæãã€ããŸããã ãã¹ãŠã®ãµãŒãã¹ãGETã§ã®ã¿ç§ã®ããã«åããããã«ããããã¯åŒãç¶ãããã§ãããããªãèªèº«ã®PUTãšDELETEã«èŠããã§ãããã
ãã¡ãããèªåã§ãµãŒãã¹ãèªç±ã«æžãããšãã§ããŸãã ãã ãããµãŒããŒãšã¯ã©ã€ã¢ã³ãã®éã«ã¯ãåãDCå ã§ç©ççã«é£ãåã£ãŠããŠãããã©ãŠã¶ããããã·ãã«ãŒã¿ãŒãç°ãªãããã°ã©ãã³ã°èšèªããã³ç°ãªãOSã§ã®HTTPãããã³ã«å®è£ ãªã©ãèšå€§ãªæ°ã®ãããã¯ãŒã¯ãšãŒãžã§ã³ããååšããããšã«æ³šæããŠãã ãããDPIæ©åšãããã€ããŒãªã©ã ãããã®ãã©ã¹ãŸãã¯ãã€ãã¹ã®ãšãŒãžã§ã³ãã¯ãã¹ãŠãRFCã«æ³šç®ããŠHTTPãããã³ã«ãå®è£ ããŠããŸãã
çªç¶ã¯ã©ã€ã¢ã³ãã®ãã©ãŠã¶ãŒãæã®GETãªã³ã¯ãšãã©ãŠã³ããŒãæåŠããå Žå-ããã¯ããªãã®ããã«ãªããŸããã¡ãŒã«ãŒã«é£çµ¡ããã®ã¯ç¡æå³ã§ãã GETãªã¯ãšã¹ãã䜿çšããŠãéã転éããããã°ã©ãã³ã°èšèªã§HTTPãããã³ã«ãå®è£ ãããšãè¿é£ã®ã«ãŒã¿ãŒããã®å¿çãåŸ ããã«ããªã¯ãšã¹ããç¹°ãè¿ãããã©ã³ã¶ã¯ã·ã§ã³ã2åå®è¡ããããšã«ãªããŸãã
ããããããã¯äž»èŠãªããšãããããŸããã HTTPãã±ãããå³å¯ã«å¶åŸ¡ãããç°å¢ãæ©ããŠãããšããŸãããã éåããæšå¥šäºé ãšãã®çç±ãä»ã®éçºè ã«ã©ã®ããã«èª¬æããŸããïŒ ãã®GETãªã¯ãšã¹ããç¹°ãè¿ãããšã¯ã§ãããã¹ããŒã¿ã¹400ã¯ã¯ã©ã€ã¢ã³ããšã©ãŒãæå³ããªãããšãååã¯ã©ã®ããã«ç解ããå¿ èŠããããŸããïŒ æšå¥šäºé ãšã¯ç°ãªããå®éã«ã¯ãç¬èªã®ã»ãã³ãã£ã¯ã¹ã䜿çšããŠãäœããã®ç¬èªã®HTTPæ¹èšãäœæãããã³ã«äœæããŸãã å°ãªããšãææžåããããšãå¿ããªãã§ãã ãã;ïŒ
åç §ïŒ
- www.rfc-editor.org/rfc/rfc2616.txt
- tools.ietf.org/html/rfc5789
- www.w3.org/TR/webarch
- w3ctag.github.io/capability-urls
ïŒããªãã®è¬èãªäœ¿çšäººã¯ãæåŸã®ææžã®éçºã«äžå®ã®åœ¹å²ãæãããŸãããïŒ