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

Web APIについての雑談

Web APIについての雑談

よく悩むところを列挙しました

Tomohiro Nishimura

December 23, 2015
Tweet

More Decks by Tomohiro Nishimura

Other Decks in Technology

Transcript

  1. ؔϞό#9 LSUDs ͱSSKDs ▸ LSUDs (large set of unknown developers)

    ▸ ޿͘Ұൠతʹެ։͞Ε͍ͯΔ ▸ Twitter/Facebook/Instagram/ Google/etc ▸ SSKDs (small set of known developers) ▸ ݶΒΕͨൣғʹެ։͞Ε͍ͯΔ ▸ ࣗࣾΞϓϦͳͲ
  2. ؔϞό#9 SSKDs (small set of known developers) ▸ ૝ఆ͞Εͨ࢖͍ํ͔͠͞Εͳ͍ ▸

    ΞϓϦʹ࠷దԽͨ͠ܗͰఏڙͰ͖Δ ▸ ։ൃऀಉ࢜Ͱձ࿩Ͱ͖Δ ▸ ີ݁߹͕ͪ͠ ▸ ଥڠ͕ͪ͠
  3. ؔϞό#9 REST ▸ ͜͜Ͱ͸ϑΟʔϧσΟϯάͬΆ͍࿩ ▸ 1εΫϦʔϯɺ1ίʔϧͱ૬ੑѱ͍ؾ͕͢Δ ▸ ϩάΞ΢τ͸ DELETE ͳͷ͔Ͳ͏͔

    ▸ λΠτϧͷߋ৽͸ PATCHʁʁʁʁʁʁ ▸ ૢ࡞͕ႈ౳ͳΒ PUT/DELETEɺͦ͏͡Όͳ͚Ε͹POST
  4. ؔϞό#9 Ϩεϙϯε ▸ ϦιʔεΛߋ৽ͨ͠ͱ͖ͷϨεϙϯε͸ɺߋ৽લʁͦΕͱ΋ߋ৽ޙʁ ▸ ϦιʔεΛফͨ͠ͱ͖͸204? ▸ 200͚ͩΕͲϨεϙϯεཁΒͳ͍ͱ͖͸ʁ ▸ {“success”:

    true} vs {} vs ۭจࣈྻ (←͜Ε͸ͳ͍) ▸ ഑ྻΛฦ͢ͱ͖ʹ΋ΦϒδΣΫτʹ͢Δ͔Ͳ͏͔ ▸ ͜Ε͸ηΩϡϦςΟͷ໰୊͕͋ΔͷͰΦϒδΣΫτͰ ▸ ඞཁͳཁૉ͚ͩʁ֦ுੑΛߟ͑ͯଟΊʹ΋Β͓ͬͯ͘ʁ ▸ {“user”: { id: 1, name: “hoge”}} vs {“user_id”: 1, “user_name”: “hoge”} ▸ ೔෇ͷϑΥʔϚοτͲ͏͢Δͷ͔ ▸ ϖʔδϯάͲ͏͢Δͷ͔ ▸ JSONͳͷ͔ଞͷϑΥʔϚοτͳͷ͔
  5. ؔϞό#9 ΤϥʔϨεϙϯε ▸ ϑΥʔϚοτ͸ݻఆ͍ͨ͠ ▸ ϝοηʔδΛ;͘ΊΔ vs ΞϓϦͰੜ੒ ▸ ଟݴޠԽͲ͏͢Δ͔ɺߋ৽͠΍͢͞͸Ͳ͏͔

    ▸ ΞϓϦଆͰΤϥʔʹର͢ΔέΞ͕ͻͭΑ͏͕Ͳ͏͔ ▸ Τϥʔίʔυඞཁͳͷ͔ ▸ Ͳ͜·Ͱ৘ใ͕͍Δͷ͔
  6. ؔϞό#9 ҉߸Խ,೉ಡԽ ▸ Ӆ͍ͨ͠৘ใΛӅ͢ ▸ ୈࡾऀʹରͯ͠(ݸਓ৘ใ)ɺ࢖༻ऀʹରͯ͠ (ήʔϜͱ͔) ▸ HTTPSͩͱ͍͍ͩͨ҆৺ ▸

    ಺༰Λ೉ಡԽͯ͠όΠφϦͰૹΔͱ͔ ▸ ΞϓϦଆͰσίʔυ͢Δͷେม໰୊ ▸ σίϯύΠϧ͞Εͨͱ͖ͷରࡦ ▸ ૬ख͸CIA͡Όͳͯ͘ૉਓ
  7. ؔϞό#9 όʔδϣϯ ▸ ޙํޓ׵ੑΛอ͍ͪͨ ▸ όʔδϣϯΛࢦఆ͢Δ͜ͱͰϨεϙϯεΛฦ͠Θ͚Δ ▸ /v1/hoge/piyo, ?version=1, X-API-Version:

    1, application/ vnd.example.v1+json ▸ Ͳ͏΍ͬͯ؅ཧ͢Δ͔ ▸ ผͷϑΝΠϧͰ؅ཧ͢Δ ▸ ifจͰ෼ذ͢Δ ▸ ݹ͍όʔδϣϯΛ͍ͭഇࢭ͢Δ͔
  8. ؔϞό#9 ඇޓ׵ͳมߋ ▸ ਃ੥Ͳ͏͢Δͷ͔ ▸ ਃ੥༻ͷαʔόʔΛ༻ҙͯͦͪ͠Βʹ޲͚Δ ▸ ΤϯυϙΠϯτΛฦ͢API (HATEOASʹͭͳ͕Δ) ▸

    ਃ੥࣌ͷΈຊ൪ͱผͷ΋ͷݟͤΔͷͲ͏ͳͷ͔ ▸ ͪͳΈʹ͸ͯͳͰ͸΍ͬͯͳ͍ ▸ ڧ੍όʔδϣϯΞοϓ ▸ ΞϓϦͷόʔδϣϯΛ্͛ͳ͍ͱ࢖͑ͳ͘͢Δ