RESTの力 / The Power of REST

RESTの力 / The Power of REST

HTTPはRPCではなく、RESTはHTTP上のCRUDシステムではありません。RESTはハイパーメディアアフォーダンスという発見性を持ち、進化可能性(evolvability)、スケーラビリティ、自己記述性、といったアプリケーションをパワフルにする力を持ちます。

PHPカンファレンス大阪(2014)での基調講演「全てを結ぶ力」、翌年福岡での基調講演「全てを結ぶ力」に続く"全てを結ぶ力三部作"の完結編。

Aad26cd7119bd8c0c2bbea107515716d?s=128

Akihito Koriyama

March 30, 2019
Tweet

Transcript

  1. 3&45ͷྗ ܊ࢁতਔ

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

  3. 
 Hypertext


  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. Ted Nelson
 Hypertext
 Hypermedia
 
 1963 http://dc-mrg.english.ucsb.edu/conference/CNCSC/multimedia/documents/wardrip-fruin.pdf

  6. Douglas Engelbart
 oN-Line System (NLS)
 1968 https://en.wikipedia.org/wiki/The_Mother_of_All_Demos

  7. Bill Atkinson
 
 HyperCard 1984 https://en.wikipedia.org/wiki/HyperCard

  8. Information Management: A Proposal Tim Berners-Lee, CERN March 1989 WorldWideWeb:

    Proposal for a HyperText Project T. Berners-Lee/CN, R. Cailliau/ECP November 1990 https://www.w3.org/History/1989/proposal.html https://www.w3.org/Proposal.html
  9. Tim Berners-Lee WWW 
 1991 https://www.w3.org/People/Berners-Lee/

  10.  WWW = Hypertext + Internet https://fukuno.jig.jp/826

  11. • HTML • URI • HTTP 


  12. https://groups.google.com/d/msg/comp.infosystems.www.authoring.cgi/-/M9FkTUVDfcwJ

  13. WebObjects 1996 WebObjects 1996 http://everystevejobsvideo.com/steve-jobs-presents-webobjects-at-mspdc-1996-2/

  14. Roy T Fielding REST
 2000 https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

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

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

  17. •REST API͸ݻఆͷϦιʔε໊΍֊૚Λఆٛͯ͠ ͸ͳΓ·ͤΜɻ… ͦͷ୅ΓʹͲͷΑ͏ʹURIΛ ૊ΈཱͯΔ͔Λࢦࣔ͠·͢ɻ •Ϧιʔεͷදݱ΍ΞϓϦέʔγϣϯঢ়ଶͷۦಈ ʹ࢖༻͞ΕΔϝσΟΞλΠϓͷఆٛɺ·ͨ͸طଘ ͷඪ४ϝσΟΞλΠϓʹର͢Δ֦ுϦϨʔγϣϯ ໊΍ϋΠύʔςΩετରԠϚʔΫΞοϓͷఆٛ ʹɺͦͷهड़తͳ౒ྗͷ΄ͱΜͲ͢΂ͯΛඅ΍

    ͢ඞཁ͕͋Γ·͢ http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
  18. https://www.ca.com/content/dam/ca/jp/files/ebook/a-guide-to-rest-and-api-design.pdf

  19. https://mooreniemi.github.io/3_models_of_apis/#/fragments

  20. શͯͷϞσϧ͸ؒҧ͍ͬͯΔɺ
 ͕ͩதʹ͸໾ཱͭ΋ͷ΋͋Δ
 
 — Box, George E. P. 


  21. l3&45GVM63*z

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

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

  24. https://youtu.be/pspy1H6A3FM

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

  26. "1*7FSTJPOJOH

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

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

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

  30. ౷ҰΠϯλʔϑΣΠεͱ͸
 )551ϝιουΛ$36%ʹϚοϐϯά͢Δࣄ 
 lϦιʔεʹର͢Δૢ࡞͸ɺʜ̐ͭͷϝιου Λఏڙ͍ͯ͠Δz 2007 https://books.google.co.jp/books?id=-7iMOLUQDqQC&pg=PA200&lpg=PA200&dq=REST+ %22%E7%B5%B1%E4%B8%80%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%BC%E3%83%95%E3%82%A7%E3%82%A4%E3%82%B9%22&source=bl&ots=NIK Kf8qSOQ&sig=ACfU3U1E- lkPNbf9mxDDdfmaEPLUqVg61Q&hl=ja&sa=X&ved=2ahUKEwiuj4Gg7JnhAhUDCqYKHU_4AIgQ6AEwBnoECAgQAQ#v=onepage&q=REST%20%22%E7%B5%B1%

    E4%B8%80%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%BC%E3%83%95%E3%82%A7%E3%82%A4%E3%82%B9%22&f=false 3&45"1*$36%PWFS)551XJUIQSFUUZ63*
  31. REpresentational State Transfer
 
 = Ϧιʔεͷ͜ͱ ͚ͩ͡Όͳ͍ͷ ? https://qiita.com/NagaokaKenichi/items/0f3a55e422d5cc9f1b9c

  32. “architectural style for 
 distributed hypermedia systems” https://www.ics.uci.edu/~fielding/pubs/dissertation/introduction.htm

  33. 3FTPVSDF4UBUF "QQMJDBUJPO4UBUF Ϧιʔεঢ়ଶදݱ
 ࣍ͷΞΫγϣϯ 3FRVFTU w4BGF w6OTBGF Server ΞΫγϣϯ 


    B
 GPSN Client
  34. https://www.programmableweb.com/news/how-guardian-approaching-hypermedia-based-api-infrastructure/2015/04/27

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

  36. https://www.slideshare.net/evolve_conference/201308-fielding-evolve "ΞϓϦέʔγϣϯঢ়ଶΛۦಈ"͢ΔͨΊͷϋΠύʔςΩετ
 = HATAOAS https://www.howtopronounce.com/hateoas/

  37. https://www.infoq.com/jp/articles/webber-rest-workflow ༗ݶঢ়ଶػց '4. http://www.comp.tmu.ac.jp/morbier/newcomparch/FSM00.html

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

    63*  wදݱʹΑΔϦιʔεૢ࡞ wࣗݾهड़తϝοηʔδ wϋΠύʔϝσΟΞ੍໿ )"5&0"4 3&45ʢ'JFMEJOHʣ੍໿ "38 https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
  39. https://martinfowler.com/articles/richardsonMaturityModel.html

  40. $BDIF RFC7243 https://tools.ietf.org/html/rfc7243

  41. l࠷ߴͷΞϓϦέʔγϣϯύϑΥʔϚϯε͸
 ωοτϫʔΫΛ࢖Θͳ͍࣌ʹಘΒΕΔz The best application performance is obtained by not

    using the network. https://www.ics.uci.edu/~fielding/pubs/dissertation/net_app_arch.htm
  42. None
  43. None
  44. https://www.cloudflare.com/learning/cdn/glossary/what-is-cache-control/ $BDIFΛίϯτϩʔϧ͢Δͷ͸αʔόʔ ΩϟογϡΛߦ͏ͷ͸ΫϥΠΞτ

  45. Server (&5CPPL
 "DDFQU-BOHVBHF+" + $BDIF$POUSPMFNBYBHF 7BSZ"DDFQU-BOHVBHF (&5CPPL
 "DDFQU-BOHVBHF+" ඵ༗ޮ https://www.slideshare.net/InfoQ/caching-hypermedia-apis

  46. ৚݅෇͖ϦΫΤετ RFC7232 https://tools.ietf.org/html/rfc7232

  47. https://www.slideshare.net/InfoQ/caching-hypermedia-apis/35

  48. Cache-Controle: public

  49. $ System GET /cat
 Cache-Controle: public,max-age=3600 GET /cat 200 OK

  50. Framework
 +
 Application Etag GET /cat ETag: 3 3 batch

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

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

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

  54. Ωϟογϡઃܭ w 55-ʢ༧ଌՄೳʣ&5BHʢෆՄ஌ʣ w QVCMJD QSJWBUF  w OPDBDIFΩϟογϡར༻ʹඞͣ֬ೝ w

    OPTUPSFΩϟογϡΛอଘ͠ͳ͍
  55. https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=ja

  56. $BDIF

  57. ࣗݾهड़తϝοηʔδ )551ϝοηʔδ͸ड৴ऀ͕ཧղ͢ΔͨΊʹඞཁͳ͢΂ͯͷ৘ใΛؚΉ

  58. .FEJB5ZQF RFC 6838 https://tools.ietf.org/html/rfc6838

  59. • text/html (hypermedia) • application/json • application/hal+json (hypermedia)
 
 •

    application/problem+json • vnd.amundsen.maze+xml (OFSJD %PNBJOTQFDJpD
  60. https://www.iana.org/assignments/media-types/media-types.xhtml

  61. https://tools.ietf.org/html/draft-ietf-appsawg-http-problem-03

  62. application/prs.koriym.travel+json
 https://tools.ietf.org/html/rfc6838#section-3.3 https://tools.ietf.org/html/rfc6838#section-3.4 application/x.koriym.travel+json Personal or Vanity Tree Unregistered x.

    Tree
  63. rel="profile" RFC 6906 https://tools.ietf.org/html/rfc6906

  64. $ 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
  65. rel="describedby" https://json-schema.org/latest/json-schema-core.html#rfc.section.10.1

  66. HTTP/1.1 200 OK
 Content-Type: application/json
 Link: <http://example.com/todo.json>; rel="describedby" {
 "id":

    123,
 “title": “Shopping” 
 } https://json-schema.org/latest/json-schema-core.html
  67. UPEPKTPO {
 ”$id”: “http://example.com/todo.json",
 "$schema": "http://json-schema.org/draft-07/schema#",
 "title": "Todo",
 "type": "object",


    "properties": {
 "id": {
 "type": "type": "string",
 "description": "The unique identifier for todo."
 },
 "title": {
 "type": "string",
 "description": "The title of the todo",
 "minLength": 3,
 "maxLength": 255
 }
 }
  68. /BNJOH There are only two hard things in Computer Science:

    cache invalidation and naming things.
 -- Phil Karlton
  69. pSTUOBNF  pSTU@OBNF  pSTU/BNF

  70. HJWFO/BNF

  71. https://schema.org/Person

  72. ϘΩϟϒϥϦ IUUQFYBNQMFDPNNZ@QSPpMF

  73. rel = "item" https://www.iana.org/assignments/link-relations/link-relations.xhtml *"/"-JOL3FMBUJPO rel = "collection"

  74. .JDSPGPSNBUT-JOL3FMBUJPO rel="friend" http://microformats.org/wiki/existing-rel-values

  75. BQQMJDBUJPOME KTPO https://json-ld.org/spec/latest/json-ld-api-best-practices/

  76. +40/-% )ZESB https://sookocheff.com/post/api/on-choosing-a-hypermedia-format/

  77. http://gtramontina.com/h-factors/

  78. • Φϯτϩδʔ (ҙຯ) • λΫιϊϛʔ (෼ྨ) • ίϨΦάϥϑΟʔ(૬ޓ࡞༻)
 *"

  79. ࣗݾهड़తϝοηʔδ

  80. •Ϧιʔεͷදݱ΍ΞϓϦέʔγϣϯঢ়ଶͷۦಈ ʹ࢖༻͞ΕΔϝσΟΞλΠϓͷఆٛɺ·ͨ͸طଘ ͷඪ४ϝσΟΞλΠϓʹର͢Δ֦ுϦϨʔγϣϯ ໊΍ϋΠύʔςΩετରԠϚʔΫΞοϓͷఆٛ ʹɺͦͷهड़తͳ౒ྗͷ΄ͱΜͲ͢΂ͯΛඅ΍ ͢ඞཁ͕͋Γ·͢ http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

  81. r3PZ5'JFEMJOH lཧղڞ༗ʹয఺Λ౰ͯΔz GPDVTJOHPOBTIBSFEVOEFSTUBOEJOH

  82. .FEJB5ZQF 1SPpMF 4UBUF -JOL 3FTPVSDF SFM SFM TDIFNBPSH *"/" ϚΠϘΩϟϒϥϦ

  83. l3&45ͱ͸શͯΛ݁Ϳྗz

  84. https://intertwingled.org/jp/ ࢲ͕ͨͪͳʹ͔ΛͻͱͭͱΓ͋͛Α͏ͱ͢Δͱ
 ͦΕ͕·ΘΓͷੈքͷ͢΂ͯͱҾ͔Ε߹͏Α͏ʹ ͭͳ͕͍ͬͯΔ͜ͱʹؾͮ͘ɻ 
 —δϣϯɾϛϡʔΞ

  85. Credit: From Nelson, Computer Lib/Dream Machines (Courtesy of Theodor Holm

    Nelson) ͢΂͕ͯਂ͘ࡨ૰͍ͯ͠Δ https://link.springer.com/chapter/10.1007/978-3-319-16925-5_13
  86. Project Xanadu
 1960 - 2014 http://www.xanadu.net/

  87. http://xanadu.com/XanaduSpace/btf.htm