WP REST APIで実際何が嬉しいの?

5a8bcda4469fae633e3e934b3ec3774b?s=47 tanshio
June 24, 2017

WP REST APIで実際何が嬉しいの?

サンプルのブログURL
https://tanshio.net

5a8bcda4469fae633e3e934b3ec3774b?s=128

tanshio

June 24, 2017
Tweet

Transcript

  1. WP REST APIͰ ࣮ࡍͳʹ͕خ͍͠ͷʁ WordCamp Kyoto 2017 WordCamp Kyoto 2017

  2. PROFILE SENDAI — ୮໺ᠳଠ WebⰋ菙ؿٔ٦ٓٝأ WP娖10䎃 !tanshio ը૾Ҿ༻ݩɿIUUQKPKPGFTDPN͍Β͢ͱ΍

  3. w813&45"1*Λ஌Βͳ͍ w813&45"1*Λ࢖ͬͯΈ͍ͨ wαΠτ΍ϒϩάͰ࢖͍͍ͨ wΞϓϦҎ֎ͷࣄྫΛ஌Γ͍ͨ ηογϣϯͷର৅

  4. WP REST APIͬͯ ͦ΋ͦ΋ͳʹʁ ׉׮׉׮וְֲֲ׮ךזך

  5. ABOUT WP REST API ͱ͸ ɾWP4.7 ͰίΞʹϚʔδ͞ΕͨΑ ɾσʔλͷऔಘͱૹ৴͕؆୯ʹͳͬͨΑ ɾURL Ͱػೳ͕มΘΔΑ

    http://ja.wp-api.org/
  6. ABOUT WP REST API ͷ໾ׂ͸جຊతʹ2ͭ ر٦ةך《䖤 ˖ 䫎珲ך《䖤 ˖ 嗚稊

    ˖ ؕذ؞ٔ٦䞔㜠ך《䖤 ر٦ةך鷏⥋ ˖ 倜鋉ر٦ةך⡲䧭 ˖ ⚺ח،فٔ؛٦ءّٝה ׃ג⢪ֲ㜥さח欽ְ׷
  7. ࠓ೔ͷηογϣϯ͸ɺ σʔλͷऔಘ͕ϝΠϯͰ͢

  8. ࣮ࡍʹ࢖ͬͯΈΑ͏ʂ

  9. TRY σʔλͷऔಘํ๏ 81ઃஔ৔ॴ/wp-json/wp/v2/~ ྫɿ IUUQTUBOTIJPOFUXQKTPOXQWQPTU דծUBOTIJPOFUך鎸✲♧鋮׾《䖤דֹ׷

  10. ϒϥ΢βͰදࣔͯ͠ΈΑ͏ʂ

  11. !

  12. TRY σʔλͷܗࣜ͸+40/ ΋ͬͱݟ΍͍ͨ͘͢͠ʜ ɾσʔλهड़ݴޠ ɾͨͩͷจࣈྻ ɾจࣈྻΛղੳ͢ΔࣄʹΑͬͯσʔλʹͳΔ

  13. TRY +40/Λݟ΍͘͢͠Α͏ w $ISPNF ⁃ +40/7JFXFS Φεεϝ w 'JSFGPY ⁃

    ࠷ॳ͔ΒೖͬͯΔʂ w 4BGBSJ ⁃ IUUQTHJUIVCDPNBDSPHFOFTJTKTPOWJFX TBGBSJ
  14. 鋅װֻׅז׏׋! $ISPNF +40/7JFXFS ͷྫ

  15. TRY K2VFSZBKBY \ VSMʟ81ͷઃஔ৔ॴXQKTPOXQWQPTUT UZQFHFU ^ EPOF GVODUJPO EBUB \

    DPOTPMFMPH EBUB  ^ GBJM GVODUJPO EBUB \ DPOTPMFMPH EBUB  ^  ͲͷαΠτͰ΋81ͷઃஔ৔ॴҎ֎ڞ௨ʂ ౤ߘҰཡͷऔಘྫ
  16. خ͍͠ϙΠϯτΛ ؆୯ͳαϯϓϧͰ঺հ

  17. SAMPLE 1 ΠϯΫϦϝϯλϧαʔν 813&45"1* +BWB4DSJQUͰΠϯΫ Ϧϝϯλϧαʔνͷղઆ 㴍׃ְه؎ٝز 馄知⽃ח嗚稊דֹ׷ 歗꬗鼂獳ָזְךדأي٦ؤ IUUQTHJTUHJUIVCDPNUBOTIJPBBDCCCECEGE

  18. SAMPLE 2 ແݶεΫϩʔϧɺϦετ௥Ճػೳ 813&45"1* +BWB4DSJQUͰແݶε Ϋϩʔϧͷղઆ خ͍͠ϙΠϯτ +4ͱ"1*ͷػೳ͚ͩͰͰ͖Δʂ ςʔϚͱ͔ϖʔδͱ͔1)1ͱ͔͍Βͳ͍ʂ QBHFͱQFS@QBHF͕ศརʂ

    IUUQTHJTUHJUIVCDPNUBOTIJPEBEFFCFDFBDCBFD
  19. ͭΒΈϙΠϯτ ը໘ભҠͯ͠໭ͬͨΒফ͑ͯΔͳͲɺͦ͏͍ͬͨ69Λվળ͠Α͏ͱͨ͠৔߹ɺ +BWB4DSJQUͷ஌ࣝ͸ඞཁʹͳΓ·͢

  20. ࣮ࡍʹ࢓ࣄͳͲͰ࢖ͬͯΈͨʂ

  21. ςʔϚͱͷ͋ΘٕͤλΠϓ Ϛοϓϐϯɺ΋͘͠͸ϦετΛΫϦ οΫ͢Δͱɺ"1*ͰίϯςϯπΛऔ ಘ͠ɺϚʔΧʔ಺ʹදࣔ͞ΕΔɻ خ͍͠ϙΠϯτ ී௨ʹ)5.-ΛςʔϚ಺ʹు͖ग़͢ ͱϖʔδ͕ॏ͍͕ɺ"1*ͩͱ͍ܰɻ ͍Ζ͍Ζͳ༻్ʹ࢖͑Δɻ ͭΒΈϙΠϯτͳ͠ CASE

    1
  22. ςʔϚͱͷ͋ΘٕͤλΠϓ ΍ͬͯΔ͜ͱ͸ɺ౤ߘ*%Λऔಘ͠ɺ"1*ͰίϯςϯπΛ ݺͼग़͍ͯ͠Δ͚ͩɻ CASE 1

  23. CASE 2 ͦͷ৔Ͱฤूɾ౤ߘ خ͍͠ϙΠϯτ ͦͷ৔ͰαΫαΫฤूͰ͖Δʂʂ ͭΒΈϙΠϯτ ը૾ͷΞοϓϩʔυ ؅ཧը໘࿈ಈܥͷΧελϜϑΟʔϧυϓϥάΠϯ "$'ͳͲ ͷ࿈ܞͳͲ

    IUUQTHJUIVCDPN8PSE1SFTTHVUFOCFSH ⇡͕ग़ͨ͜ͱʹΑ͓ͬͯ໾ޚ໔ʹͳͬͨ ౤ߘͷݕূʹ͸1PTUNBO͕͓͢͢ΊͰ͢ IUUQTXXXHFUQPTUNBODPN $ISPNF֦ு͋Γ
  24. 7VFʴ81ͷ41"ϒϩά خ͍͠ϙΠϯτ ମײ͔ͳΓ͸΍͍ ͭΒΈϙΠϯτ 4&0ͰਧͬඈͿ .VMUJ%FWJDF4XJUDIFSΛ࢖ͭͯCPUΛҧ͏ςʔϚʹඈ͹͢ IUUQTKBXPSEQSFTTPSHQMVHJOTNVMUJEFWJDFTXJUDIFS 813&45"1*͕όʔδϣϯΞοϓ͢Δͱ٧Ή ঢ়ଶ؅ཧ͕΍͹͍ ͜Ε͸΍Δඞཁ͕͋Δͷ͔ͱ೰Ή

    813&45"1*Λ༻͍ͨ41"ϒϩά CASE 3
  25. ؤுͬͨͱ͜Ζ ͍Βͳ͍ཁૉΛVOTFUͰফͯ͠ߴ଎Խʂ ٙ໰఺ ࢲͷαΠτͰ͸+40/ΛຒΊࠐΜͰߴ଎ԽΛਤ͍ͬͯΔͷͰ͕͢ɺ OFX81@3&45@3FRVFTU ΋81@3&45@3FRVFTUGSPN@VSMͰ΋@FNCFEͷ಺༰͕͠ Ύͱ͘Ͱ͖͍ͯ·ͤΜʜ ࢓ํ͕ͳ͍ͷͰpMF@HFU@DPOUFOUT Ͱ"1*ʹΞΫηε͍ͯ͠ΔͷͰ͕͢ɺ ୭͔ղܾࡦ͕͋ͬͨΒڭ͍͑ͯͩ͘͞ʂ

    813&45"1*Λ༻͍ͨ41"ϒϩά CASE 3
  26. ·ͱΊ

  27. SUMMARY ·ͱΊ wҙ֎ͱ؆୯ʹ࢖͑Δ w༻్͸༷ʑ w81ͰγʔϜϨεͳαΠτΛ࡞੒ͨ͠ ͍৔߹ʹศརʂ w69Λߟ͑Δͱ݁ߏେมͳ৔໘΋ +BWB4DSJQUͷ஌͕ࣝඞཁʹɻ͜ͷػձʹ+BWB4DSJQUͱ஥ྑ͘ͳΖ͏ʂ

  28. ·ͣ͸खܰʹ͸͡ΊͯΈΑ͏ʂ ͓ͳ͡ΈϓϥάΠϯ$POUBDU'PSN΋813&45"1*Λ࢖ͬͯΔʂ ϓϥάΠϯ։ൃͰ΋ࠓޙελϯμʔυʹͳΓͦ͏ͳ༧ײʂ

  29. ͋Γ͕ͱ͏͍͟͝·ͨ͠