REST 6+4の制約

REST 6+4の制約

Aad26cd7119bd8c0c2bbea107515716d?s=128

Akihito Koriyama

December 01, 2019
Tweet

Transcript

  1. 3&45  ͷ੍໿  ܊ࢁতਔ https://twitter.com/koriym

  2. ܊ࢁতਔ http://twitter.com/koriym

  3. )ZQFS5FYU .BSLVQ-BOHVBHF

  4. Hypertext ͱ͸  ෳ਺ͷςΩετΛ૬ޓʹؔ࿈෇͚ɺ݁ͼ෇͚Δ࢓૊Έ  http://www.ltrebing.de/studium/hypertext/hypertext.gif https://ja.wikipedia.org/wiki/%E3%83%8F%E3%82%A4%E3%83%91%E3%83%BC%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88

  5. None
  6. http://www.nextnature.net/2009/12/the-playboy-interview-marshall-mcluhan/ Marshall McLuhan (1911-1980) l୭͕ਫΛൃݟͨ͠ͷ͔஌Βͳ͍͕ɺ ͦΕ͕ڕͰͳ͍͜ͱ͚ͩ͸͔֬ͩz

  7. https://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http

  8. https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm ΞʔΩςΫνϟελΠϧͱωοτϫʔΫϕʔεͷιϑτ΢ΣΞΞʔΩςΫνϟͷઃܭɻ
 ത࢜࿦จɺΧϦϑΥϧχΞେֶΞʔόΠϯߍɺ2000೥

  9. http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven 3&45"1*͸ϋΠύʔςΩετۦಈͰ͸ͳ͍ ͱ͍͚ͳ͍ɻ ୯ͳΔ)551"1*͕3&45"1*ͱݺ͹ΕͯΔ ͜ͱʹϑϥετϨʔγϣϯΛײ͡Δɻ

  10. •REST API͸ݻఆͷϦιʔε໊΍֊૚Λ ఆٛͯ͠͸ͳΓ·ͤΜɻ… ͦͷ୅Γʹ ͲͷΑ͏ʹURIΛ૊ΈཱͯΔ͔Λࢦࣔ ͠·͢ɻ •Ϧιʔεͷදݱ΍ΞϓϦέʔγϣϯঢ় ଶͷۦಈʹ࢖༻͞ΕΔϝσΟΞλΠϓ ͷఆٛ౳ͷهड़ʹ౒ྗΛ͢Δඞཁ͕͋ Γ·͢

    http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
  11. https://developer.twitter.com/en/docs/api-reference-index

  12. https://petstore.swagger.io/

  13. http://t-code.pl/blog/2016/02/rest-misconceptions-1/

  14. https://stackoverflow.com/questions/6845772/rest-uri-convention-singular-or-plural-name-of-resource-while-creating-it

  15. https://youtu.be/pspy1H6A3FM

  16. "1*7FSTJPOJOH W

  17. https://www.slideshare.net/evolve_conference/201308-fielding-evolve

  18. https://www.slideshare.net/evolve_conference/201308-fielding-evolve

  19. https://twitter.com/fielding/status/376835835670167552

  20. https://www.ca.com/content/dam/ca/jp/files/ebook/a-guide-to-rest-and-api-design.pdf

  21. 3&45"1* )ZQFSNFEJB"1*

  22. 8FCͷ੒ޭཁҼͱͯ͠ͷ  ͭͷॏཁͳ8FCͷΞʔΩςΫνϟͷಛੑ ෼ࢄϋΠύʔϝσΟΞ ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛

  23. ௿͍ࢀೖোน w 8FCαΠτΛར༻͢Δͷ΋ɺ࡞੒͢Δͷ΋؆୯ ෼ࢄϋΠύʔϝσΟΞ ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛

  24. ֦ுੑ w ΫϥΠΞϯτͷಈ࡞ʹӨڹΛ༩͑Δࣄͳ͘ɺ8FCαΠ τΛมߋ͢Δࣄ͕Ͱ͖Δɻ ෼ࢄϋΠύʔϝσΟΞ ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛

  25. ෼ࢄϋΠύʔϝσΟΞ w σʔλͱڞʹ࣍ʹͰ͖Δૢ࡞Λαʔόʔ͕఻͑ɺ σʔλࣗମͱಉ͡Α͏ʹѻ͍·͢ɻ ෼ࢄϋΠύʔϝσΟΞ ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛

  26. Πϯλʔωοτن໛ w ແடংͳεέʔϥϏϦςΟ w ಠཱͨ͠഑උ ෼ࢄϋΠύʔϝσΟΞ ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛

  27. "1*˺8FC w " Ϋϩʔζυͳ؀ڥ w # )551 $36% 31$ 

    w $ 3&45 ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛ ௿͍ࢀೖোน ֦ுੑ ϋΠύʔϝσΟΞ ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛ Πϯλʔωοτن໛
  28. "1*˺8FC IVNBO NBDIJOF

  29. wΫϥΠΞϯτʗαʔό wεςʔτϨεੑ wΩϟογϡ w֊૚ԽγεςϜ w ίʔυΦϯσϚϯυ  w౷ҰΠϯλϑΣʔεɹ ΠϯλʔϑΣΠε੍໿ʣ wϦιʔεͷࣝผ

    63*  wදݱʹΑΔϦιʔεૢ࡞ wࣗݾهड़తϝοηʔδ wϋΠύʔϝσΟΞ੍໿ )"5&0"4 3&45ʢ'JFMEJOHʣ੍໿ 29 https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm ΞʔΩςΫνϟ੍໿ ΠϯλʔϑΣΠε੍໿
  30. ͭͷΠϯλʔϑΣΠε੍໿

  31. ౷ҰΠϯλʔϑΣΠεͷޡղ w σʔλͷૢ࡞ͱ)551ϝιουͷϚοϐϯάͰ͸ͳ͍ w TUPSBHFBTBTFSWJDF $36%PWFS)551 /P 2007 2010

  32. ̐ͭͷΠϯλʔϑΣΠεͷ੍໿ wϦιʔεͷࣝผ 63*  wදݱʹΑΔϦιʔεૢ࡞ wࣗݾهड़తϝοηʔδ wϋΠύʔϝσΟΞ੍໿

  33. Ϧιʔεͷࣝผ w ౷ҰϦιʔεࣝผࢠ 63*  w ඇதԝγεςϜ 63* දݱʹΑΔૢ࡞ ࣗݾهड़తϝοηʔδ

    ϋΠύʔϝσΟΞ
  34. දݱʹΑΔϦιʔεૢ࡞ w Ϧιʔεͱ͸දݱՄೳͳԿͰ΋ w දݱͷ࣮ଶ͸ωοτϫʔΫͰసૹՄೳόΠτྻ w ඪ४Խ͞ΕͨHTTPϝιουʢGETͱPOSTʣͷηοτ Λ࢖༻ͯ͠ަޓʹදݱΛૹ৴͢Δ͜ͱʹΑͬͯϦιʔ εΛૢ࡞ 63*

    දݱʹΑΔૢ࡞ ࣗݾهड़తϝοηʔδ ϋΠύʔϝσΟΞ
  35. ࣗݾهड़తϝοηʔδ w )551ϝοηʔδ͸ड৴ऀ͕ཧղ͢ΔͨΊʹඞཁͳ ͢΂ͯͷ৘ใΛؚΉ 63* දݱʹΑΔૢ࡞ ࣗݾهड़తϝοηʔδ ϋΠύʔϝσΟΞ

  36. w )"5&0"4)ZQFSNFEJBBTUIFFOHJOFPG BQQMJDBUJPOTUBUF w ϋΠύʔϝσΟΞίϯτϩʔϧ͸ɺΞϓϦέʔγϣϯঢ়ଶ ͷมԽͷݪಈྗ ϋΠύʔϝσΟΞ੍໿ ΞϓϦέʔγϣϯঢ়ଶͷΤϯδϯͱͯ͠ͷϋΠύʔϝσΟΞ) 63* දݱʹΑΔૢ࡞

    ࣗݾهड़తϝοηʔδ ϋΠύʔϝσΟΞ
  37. 'JOJUF4UBUF.BDIJOF ༗ݶঢ়ଶػց

  38. 3FTPVSDF4UBUF "QQMJDBUJPO4UBUF Ϧιʔεঢ়ଶදݱ 3FRVFTU w4BGF w6OTBGF /FYU"DUJPO  B GPSN

    3FQSFTFOUBUJPOBM4UBUF
  39. ͭͷΠϯλʔϑΣΠε੍໿

  40. ͭͷΞʔΩςΫνϟ੍໿

  41. /6--੍໿ w ੍໿͕ଘࡏͤͣίϯϙʔωϯτΛִͯΔ΋ͷ͕ͳ͍ঢ়ଶ w ̎ͭͷઃܭͷϓϩηε w ίϯϙʔωϯτ͔Βߏஙɺ૑଄ੑͱແݶͷϏδϣϯΛڧௐ w ઃܭۭؒΛ۠ผ੍͠໿Λద༻͢Δɺ཈੍ͱཧղΛڧௐɹ

  42. ΫϥΠΞϯτʗαʔό w ௨৴͸ରɻ w ಠཱͨ͠௨৴ɻ $4 4UBUFMFTT $BDIF -BZFSFE $P%

    *'
  43. εςʔτϨεੑ w ϦΫΤετؒ͸ແؔ܎ $4 4UBUFMFTT $BDIF -BZFSFE $P% *'

  44. Ωϟογϡ w ࠷ߴͷύϑΥʔϚϯε͸ωοτϫʔΫΛ࢖Θͳ͍ࣄ $4 4UBUFMFTT $BDIF -BZFSFE $P% *'

  45. None
  46. None
  47. $ $ $ $

  48. NBYBHF

  49. (&5CPPL + $BDIF$POUSPMNBYBHF (&5CPPL ඵ༗ޮ $

  50. (&5CPPL "DDFQU-BOHVBHF+" + $BDIF$POUSPMNBYBHF 7BSZ"DDFQU-BOHVBHF (&5CPPL "DDFQU-BOHVBHF&/ & $BDIF$POUSPMNBYBHF 7BSZ"DDFQU-BOHVBHF

  51. ৚݅෇͖ϦΫΤετ

  52. (&5DBU &5BH (&5DBU *G/POF.BUDI /PU.PEJpFE 

  53. (&5DBU &5BH (&5DBU *G/POF.BUDI 0,&UBH  

  54. Cache-Control: public

  55. $ $ $ $BDIF$POUSPM QVCMJD $BDIF$POUSPM QSJWBUF $

  56. Etag GET /cat ETag: 3 batch FW + APP 

  57. None
  58. None
  59. Cache-Control: 
 max-age=0,
 private, 
 must-revalidate ຊ౰ʹ ? https://<censored>.com/recipe/1416377

  60. http://bearsunday.github.io/manuals/1.0/ja/http-cache.html

  61. guzzle-cache- middleware https://github.com/Kevinrob/guzzle-cache-middleware

  62. Ωϟογϡઃܭ w OPTUPSF  ΩϟογϡෆՄೳʁʣ w OPDBDIF ʢ౎౓֬ೝඞཁʁʣ w QVCMJD

    QSJWBUF  w NVTUSFWBMJEBUF ʢظݶ੾Ε࢖͑Δʁ  w NBYBHF  w &5BHΛ෇Ճ https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=ja
  63. ֊૚ԽγεςϜ w )551γεςϜͷதͷίϯϙʔωϯτ w ಁ໌ͳૢ࡞ $4 4UBUFMFTT $BDIF -BZFSFE $P%

    *'
  64. ʢίʔυΦϯσϚϯυʣ w Ϧιʔεͷॲཧͷϊ΢ϋ΢ΛΫϥΠΞϯτͰ࣮ߦ $4 4UBUFMFTT $BDIF -BZFSFE $P% *'

  65. ͭͷΞʔΩςΫνϟ੍໿

  66. 8FCͷ੒ޭཁҼ ௿͍ࢀೖোน WebΛ࢖͏ํ๏ΛֶͿͷ͸؆୯ͰɺWebαΠτΛߏங͢Δͷ΋؆୯Ͱ͢ɻ ֦ுੑ ݸʑͷWebαΠτ͸ɺΫϥΠΞϯτΛյ͢͜ͱͳ͘ɺҰ൩Ͱมߋ͢Δ͜ͱ͕Ͱ͖·͢ɻ਺े೥ ʹΘͨͬͯɺWebͷશମ͸େ෯ʹมߋ͞Ε·͕͢ɺجૅͱͳΔٕज़͸͢΂ͯ͋·ΓมԽ͠·ͤ Μɻ ෼ࢄϋΠύʔϝσΟΞ ΫϥΠΞϯτ͕αʔόͷσʔλͰͰ͖Δ͜ͱʹ͍ͭͯͷ৘ใ͸ɺσʔλͱಉ͡৔ॴʹอ࣋͞Ε ͯɺಉ͡υΩϡϝϯτͰΫϥΠΞϯτʹૹ৴͞Ε·͢ɻ

    Πϯλʔωοτن໛ γεςϜͷ෦෼ಉ࢜ʹ௕ظతͳؔ܎͸ͳ͘ɺҟͳΔ෦෼͸ҟͳΔ଎౓ͰมԽͰ͖·͢ɻ http://restfulwebapis.com
  67. ̐ͭͷΠϯλʔϑΣΠεͷ੍໿ w Ϧιʔεͷࣝผ 63*  w දݱʹΑΔϦιʔεૢ࡞ w ࣗݾهड़తϝοηʔδ w

    ϋΠύʔϝσΟΞ੍໿
  68. ͭͷΞʔΩςΫνϟ੍໿ ΫϥΠΞϯτʗαʔό Webͷશͯͷ௨৴͸ɺ1ର1Ͱ͢ɻ εςʔτϨε ΫϥΠΞϯτ͕ݱࡏϦΫΤετΛߦ͍ͬͯͳ͍ͱ͖͸ɺαʔό͸ͦͷଘࡏΛ஌Γ·ͤΜɻ Ωϟογϡ ΫϥΠΞϯτ͸Ωϟογϡ͔ΒҎલͷϨεϙϯεΛ࠶ར༻͢Δ͜ͱͰɺωοτϫʔΫ্ͷҠಈΛอଘ͢Δ͜ ͱ͕Ͱ͖·͢ɻ ֊૚ԽγεςϜ ϓϩΩγͷΑ͏ͳ஥հऀ͸ɺΫϥΠΞϯτͱαʔόͷؒʹݟ͑ͳ͍Α͏ʹૠೖ͢Δ͜ͱ͕Ͱ͖·͢ɻ

    ίʔυΦϯσϚϯυ αʔό͸ɺσʔλʹՃ࣮͑ͯߦՄೳͳίʔυΛૹ৴͢Δ͜ͱ͕Ͱ͖·͢ɻ͜ͷίʔυ͸ɺΫϥΠΞϯτ͕Ϧ ΫΤετͨ͠ͱ͖ʹࣗಈతʹ഑උ͞ΕɺͦΕ͕มߋ͞Εͨ৔߹͸ࣗಈతʹ࠶഑උ͞Ε·͢ɻ http://restfulwebapis.com
  69. 1.ඞཁͳΞʔΩςΫνϟͷಛੑΛׂΓग़͠·͢ɻ 2.ͦΕʹඞཁͳ੍໿ͷબఆΛͯ͠ɺҰॹʹಈ͘ϓϩτίϧͱଞͷඪ४ͷηοτΛઃ ܭ͠·͢ʢHTTPɺURIɺHTMLɺJavaScriptʣ γεςϜઃܭઓུ http://restfulwebapis.com ෼ࢄϋΠύʔϝσΟΞ ௿͍ࢀೖোน ֦ுੑ Πϯλʔωοτن໛

  70. https://etc9.hatenablog.com/entry/2019/11/06/090000

  71. 3&45"1*ઃܭ

  72. None
  73. $ curl -i http://example.com 
 HTTP/1.1 200 OK Content-Type: application/json

    Link: <http://example.com/profile>; rel="profile" { "wtl": "MjAxMy0wNS0wNiAxMjo1Nzo1MyAtMDcwMA==\n", “grobb34s": […] } $ curl -i http://example.com/profile
 HTTP/1.1 200 OK Content-Type: text/plain 
 The Example.com API =================== Example.com provides access to our blog through an API. In the API, you'll see two major things of interest: `wtl` and `grobb34s` ## wtl The value provided under the `wtl` key is the time the latest blog post was posted, in "%Y-%m-%d %H:%M:%S %z" format. This value is then Base64 encoded. http://www.designinghypermediaapis.com/blog/the-profile-link-relation-and-you.html
  74. http://alps.io/

  75. wҙຯతهड़ࢠ w෼ྨ wؔ܎

  76. None
  77. #BDLFOE%FW 10 %#%FW 'SPOU%FW "1*%FTJHO 6*%FTJHO

  78. .FEJB5ZQF 1SPpMF 4UBUF $USM 3FTPVSDF SFM SFM TDIFNBPSH *"/" ϚΠϘΩϟϒϥϦ

  79. ࢲͨͪͷ࢓ࣄ *OUFSOFU1SPHSBNJOH1SPHSBNJOH*OUFSOFU

  80. r3&45GVM8FC"1* ೥Ҏ্ʹΘͨͬͯ8FC͸ϢʔβʔΛ޾෱ʹͯ͠ ͖ͨɻԯυϧن໛ͷఇࠃͷ༷ͳاۀ͕ݱΕͯ͸ ফ͍͕͑ͯͬͨͦΕΒ͸શͯಉ̐ͭ͡ͷٕज़Λ ࢖͍ͬͯͨɻ )551 63* )5.- BOE+BWB4DSJQU http://restfulwebapis.com

  81. !NBNVOE !38"#PPL !ULBXB UBML !LPSJZN ͜ͷεϥΠυ͸'JFMEJOHࢯͷ࿦จͱɺॻ੶ʮ3&45GVM8FC"1*TʯͰ.JLF"NVOETFOࢯ͕ 'JFMEJOHത࢜ͷ3&45࿦จΛʮ"O"1*%FTJHOFS`T(VJEFUPUIF'JFMEJOH%JTTFSUBUJPOʯ ͱͯ͠঺հ͍ͯ͠ΔষΛݩʹͯ͠͞ΒʹղઆΛՃ͑ͨ΋ͷͰ͢ɻ TQFDJBMUIBOLT