Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RESTの力 / The Power of REST

RESTの力 / The Power of REST

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

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

Akihito Koriyama

March 30, 2019
Tweet

More Decks by Akihito Koriyama

Other Decks in Technology

Transcript

  1. 3&45ͷྗ
    ܊ࢁতਔ

    View Slide

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

    View Slide


  3. Hypertext


    View Slide

  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

    View Slide

  5. Ted Nelson
 Hypertext

    Hypermedia


    1963
    http://dc-mrg.english.ucsb.edu/conference/CNCSC/multimedia/documents/wardrip-fruin.pdf

    View Slide

  6. Douglas Engelbart

    oN-Line System (NLS)

    1968
    https://en.wikipedia.org/wiki/The_Mother_of_All_Demos

    View Slide

  7. Bill Atkinson


    HyperCard 1984
    https://en.wikipedia.org/wiki/HyperCard

    View Slide

  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

    View Slide

  9. Tim Berners-Lee
    WWW 

    1991
    https://www.w3.org/People/Berners-Lee/

    View Slide


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

    View Slide

  11. • HTML
    • URI
    • HTTP 


    View Slide

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

    View Slide

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

    View Slide

  14. Roy T Fielding
    REST

    2000
    https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

    View Slide

  15. ΞʔΩςΫνϟελΠϧͱωοτϫʔΫϕʔεͷιϑτ΢ΣΞΞʔΩςΫνϟͷઃܭɻ

    ത࢜࿦จɺΧϦϑΥϧχΞେֶΞʔόΠϯߍɺ2000೥
    https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

    View Slide

  16. http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
    3&45"1*͸ϋΠύʔςΩετۦಈͰ͸ͳ͍ͱ͍͚ͳ
    ͍ɻ

    ୯ͳΔ)551"1*͕3&45"1*ͱݺ͹ΕͯΔ͜ͱʹϑϥ
    ετϨʔγϣϯΛײ͡Δɻ

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  20. શͯͷϞσϧ͸ؒҧ͍ͬͯΔɺ

    ͕ͩதʹ͸໾ཱͭ΋ͷ΋͋Δ


    — Box, George E. P.

    View Slide

  21. l3&45GVM63*z

    View Slide

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

    View Slide

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

    View Slide

  24. https://youtu.be/pspy1H6A3FM

    View Slide

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

    View Slide

  26. "1*7FSTJPOJOH

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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*

    View Slide

  31. REpresentational State Transfer


    = Ϧιʔεͷ͜ͱ ͚ͩ͡Όͳ͍ͷ
    ?
    https://qiita.com/NagaokaKenichi/items/0f3a55e422d5cc9f1b9c

    View Slide

  32. “architectural style for 

    distributed hypermedia
    systems”
    https://www.ics.uci.edu/~fielding/pubs/dissertation/introduction.htm

    View Slide

  33. 3FTPVSDF4UBUF
    "QQMJDBUJPO4UBUF
    Ϧιʔεঢ়ଶදݱ

    ࣍ͷΞΫγϣϯ
    3FRVFTU
    w4BGF
    w6OTBGF
    Server
    ΞΫγϣϯ 

    B

    GPSN
    Client

    View Slide

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

    View Slide

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

    View Slide

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

    = HATAOAS
    https://www.howtopronounce.com/hateoas/

    View Slide

  37. https://www.infoq.com/jp/articles/webber-rest-workflow
    ༗ݶঢ়ଶػց '4.

    http://www.comp.tmu.ac.jp/morbier/newcomparch/FSM00.html

    View Slide

  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

    View Slide

  39. https://martinfowler.com/articles/richardsonMaturityModel.html

    View Slide

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

    View Slide

  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

    View Slide

  42. View Slide

  43. View Slide

  44. https://www.cloudflare.com/learning/cdn/glossary/what-is-cache-control/
    $BDIFΛίϯτϩʔϧ͢Δͷ͸αʔόʔ
    ΩϟογϡΛߦ͏ͷ͸ΫϥΠΞτ

    View Slide

  45. Server
    (&5CPPL

    "DDFQU-BOHVBHF+"
    +
    $BDIF$POUSPMFNBYBHF
    7BSZ"DDFQU-BOHVBHF
    (&5CPPL

    "DDFQU-BOHVBHF+"
    ඵ༗ޮ
    https://www.slideshare.net/InfoQ/caching-hypermedia-apis

    View Slide

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

    View Slide

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

    View Slide

  48. Cache-Controle: public

    View Slide

  49. $
    System
    GET /cat

    Cache-Controle: public,max-age=3600
    GET /cat
    200 OK

    View Slide

  50. Framework

    +

    Application
    Etag
    GET /cat
    ETag: 3
    3
    batch

    View Slide

  51. Cache-Control: 

    max-age=0,

    private, 

    must-revalidate
    ຊ౰ʹ ?
    https://.com/recipe/1416377

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  55. https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=ja

    View Slide

  56. $BDIF

    View Slide

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

    View Slide

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

    View Slide

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


    • application/problem+json
    • vnd.amundsen.maze+xml
    (OFSJD
    %PNBJOTQFDJpD

    View Slide

  60. https://www.iana.org/assignments/media-types/media-types.xhtml

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

  64. $ curl -i http://example.com

    HTTP/1.1 200 OK
    Content-Type: application/json
    Link: ; 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

    View Slide

  65. rel="describedby"
    https://json-schema.org/latest/json-schema-core.html#rfc.section.10.1

    View Slide

  66. HTTP/1.1 200 OK

    Content-Type: application/json

    Link: ; rel="describedby"
    {

    "id": 123,

    “title": “Shopping” 

    }
    https://json-schema.org/latest/json-schema-core.html

    View Slide

  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

    }

    }

    View Slide

  68. /BNJOH
    There are only two hard things in Computer Science: cache invalidation and naming things.

    -- Phil Karlton

    View Slide

  69. pSTUOBNF
    [email protected]
    pSTU/BNF

    View Slide

  70. HJWFO/BNF

    View Slide

  71. https://schema.org/Person

    View Slide

  72. ϘΩϟϒϥϦ
    [email protected]

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    *"

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  84. https://intertwingled.org/jp/
    ࢲ͕ͨͪͳʹ͔ΛͻͱͭͱΓ͋͛Α͏ͱ͢Δͱ

    ͦΕ͕·ΘΓͷੈքͷ͢΂ͯͱҾ͔Ε߹͏Α͏ʹ
    ͭͳ͕͍ͬͯΔ͜ͱʹؾͮ͘ɻ

    —δϣϯɾϛϡʔΞ

    View Slide

  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

    View Slide

  86. Project Xanadu

    1960 - 2014
    http://www.xanadu.net/

    View Slide

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

    View Slide