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

API Study #4

3dc90859154a16826de8c3df3e4d3bce?s=47 Masato SERIZAWA
January 24, 2017
620

API Study #4

RESTful な API におけるファイルアップロードについて

3dc90859154a16826de8c3df3e4d3bce?s=128

Masato SERIZAWA

January 24, 2017
Tweet

Transcript

  1. 3&45GVMͳ"1*ʹ͓͚Δ ϑΝΠϧΞοϓϩʔυʹ͍ͭͯ ۔ᖒխਓ 5VFT CONFIDENCIAL SmartHR Engineer API Study #4

  2. CONFIDENCIAL ۔ᖒ խਓ @masato_serizawa • גࣜձࣾ KUFU ΤϯδχΞ ͰɺSmartHR ͱ͍͏αʔϏεΛ։

    ൃ͍ͯ͠·͢ • ΤϯδχΞͱͯ͠ͷΩϟϦΞͷ΄ͱΜͲΛ WebAPI ͷઃܭɾ ։ൃɾӡ༻ɾൢചΛͯ͠ա͍ͯ͝͠·͢ • ͨ·ʹ Hackathon ʹग़ͨΓ͠·͢ • झຯ͸ Data Visualization Ͱ͢
  3. ຊ೔͓࿩͢Δ͜ͱ ʰ3&45GVM"1*ʹ͓͚ΔϑΝΠϧΞοϓϩʔυʱ

  4. CONFIDENCIAL WebAPI Λ։ൃ͍ͯ͠ΔͱɺϑΝΠϧΛѻ͍͍ͨ ৔໘ʹग़͘Θ͢͜ͱ΋͋Δͱࢥ͍·͢ɻ ͨͩɺ͍͟ REST ͷ֓೦ʹϑΝΠϧͷೖग़ྗΛ౰ ͯࠐ΋͏ͱ͢Δͱɺ͍·͍ͪͬ͘͠Γͤ͞ΒΕͣɺ ೰Ή͜ͱʹͳΔͷͰ͸ͳ͍Ͱ͠ΐ͏͔ɻ ࠓճ͸࣮αʔϏεͷྫΛ౿·͑ͭͭɺϕετϓϥ

    ΫςΟεΛ୳ٻ͍ͯ͜͠͏ͱࢥ͍·͢ɻ
  5. ϑΝΠϧͷૹ৴ํ๏

  6. CONFIDENCIAL •RFC2388 Ͱఆٛ͞Ε͍ͯΔ HTTP ʹ͓͚ΔϑΝΠ ϧૹ৴ͷԦಓ •HTML ϑΥʔϜ͔ΒϑΝΠϧΛૹ৴͢ΔͨΊͷن ֨ͰɺϑΝΠϧσʔλҎ֎ʹ΋༷ʑͳσʔλΛ෇ ਵͤ͞ΒΕΔ

    •όΠφϦΛѻ͑ΔϝϦοτ͕͋Δ൓໘ɺJSON ϕʔ εͷ API ͱͷ਌࿨ੑ͸௿͍ NVMUJQBSUGPSNEBUB
  7. CONFIDENCIAL NVMUJQBSUGPSNEBUB 9O+-F;*CC(6:U[12+V $POUFOU%JTQPTJUJPOGPSNEBUBOBNFUJUMF UJUMF 9O+-F;*CC(6:U[12+V $POUFOU%JTQPTJUJPOGPSNEBUBOBNFEFTDSJQUJPO EFTDSJQUJPO 9O+-F;*CC(6:U[12+V $POUFOU%JTQPTJUJPOGPSNEBUBOBNFTUSFBN@JE

     9O+-F;*CC(6:U[12+V $POUFOU%JTQPTJUJPOGPSNEBUBOBNFJUFN@JNBHFT<>pMFOBNFTBNQMFQOH $POUFOU5ZQFJNBHFQOH $POUFOU-FOHUI \1VUCJOBSZDPOUFOUTUIBUZPVXBOUUPVQMPBE^ UBC"1*ͷαϯϓϧΑΓҾ༻
  8. CONFIDENCIAL •ϑΝΠϧσʔλΛ Base64 ΤϯίʔυͰจࣈྻԽ ͯ͠ѻ͏ •ಛʹ RFC Ͱఆٛ͞Ε͍ͯΔ΋ͷͰ͸ͳ͍͕ɺେख Web αʔϏεͷ

    API Ͱͷ࠾༻࣮੷͕͋Δ •จࣈྻͳͷͰͦͷ·· JSON ʹ٧ΊΕΔ൓໘ɺ σʔλ༰ྔ͕͔͞ΜͰ͠·͏σϝϦοτ͕͋Δ #BTF
  9. CONFIDENCIAL \ BTTFU\ LFZFYBNQMFHJG  BUUBDINFOU 58'V*(M[*(3QD3QCNEB9/P;82T*(WE$#WCNY*(+*(IQDZ#Z; 8'[CT*(+E$#JF4#B(M[ *)/QCNEC('Z*)# E87L*('V;$#QCN3M;N'B8EI:NYM*(EMCN7Z:93QCHC:HBWE

    YM;(EM-$#MF(/M;83[*)3P ;4#[B(ZE$#;8IMC87V:6HC:H:8*(/IDNIC$#XC(7ID 7Z;4 ^ ^ #BTF
  10. ϑΝΠϧͷอଘํ๏

  11. CONFIDENCIAL •ಛఆϦιʔεͷಛఆΞτϦϏϡʔτʹରͯ͠ϑΝ ΠϧσʔλΛ௚઀ૹΔํࣜ •RESTful API Ͱ͸΄ͱΜͲͷ৔߹ɺૹ৴͢ΔϑΝ Πϧσʔλ͸Կ͔͠ΒͷϦιʔεʹඥͮ͘͸ͣͳ ͷͰɺ௚ײతͱ͍͑͹௚ײత •ϑΝΠϧΛ͍͔ͭ͘ͷϦιʔεͰ࢖͍·Θ͍ͨ͠ ৔߹ʹ͸޲͍͍ͯͳ͍

    Ϧιʔεඥ෇͚ύλʔϯ
  12. CONFIDENCIAL •ϑΝΠϧΞοϓϩʔυͷΤϯυϙΠϯτΛ࡞Γɺ ͦ͜ʹલ΋ͬͯϑΝΠϧΛૹΔํࣜ •Ξοϓϩʔυͨ͠ϑΝΠϧΛ1ͭͷϦιʔεͱͯ͠ ൚༻తʹѻ͍͍ͨ৔߹ʹ༗ޮ •ଞͷϦιʔεʹඥ෇͚Δ৔߹͸ɺID ΍ URLɺύε ͳͲΛͦͷϦιʔεͷΞτϦϏϡʔτʹઃఆ͠௚ ͢ඞཁ͕͋Δ

    ൚༻ϑΝΠϧΞοϓϩʔυύλʔϯ
  13. ࣮αʔϏεͷྫ

  14. CONFIDENCIAL •Contents API ͱ͍͏൚༻ϑΝΠϧΞοϓϩʔυͷ ΤϯυϙΠϯτ͕͋Δ •͜ΕΛ࢖͏͜ͱͰɺʮίϝϯτΤϦΞʹϑΝΠϧ ΛυϥοάΞϯυυϩοϓͯͦ͠ͷ··ϚʔΫμ ΢ϯʹམͱ͠ࠐΉʯΈ͍ͨͳڍಈΛ࣮ݱ͍ͯ͠Δ ͱࢥΘΕΔ •Base64

    ͰσʔλΛૹ৴͢Δ (JU)VC"1* IUUQTEFWFMPQFSHJUIVCDPNWSFQPTDPOUFOUT
  15. CONFIDENCIAL •൚༻ϑΝΠϧΞοϓϩʔυͷΤϯυϙΠϯτ͕͋Δ •Ξοϓϩʔυ׬ྃ͢ΔͱʮϑΝΠϧΩʔʯ͕ฦͬͯ ͖ͯɺ͜ΕΛ࢖ͬͯ֘౰͢ΔΞτϦϏϡʔτΛߋ৽ ͢Δ •ΞτϦϏϡʔτͱͷͻ΋෇͖͕ͳ͍ϑΝΠϧ͸3೔ ؒͰফڈ͞ΕΔ •multipart/form-data ͰσʔλΛૹ৴͢Δ $ZCP[V"1*

    IUUQTDZCP[VEFW[FOEFTLDPNIDKBBSUJDMFT
  16. CONFIDENCIAL •Ϧιʔεඥ෇͖ܗࣜͷϑΝΠϧΞοϓϩʔυ •Base64 ͷ΄͔ɺURL-encoded binary ͱ URL ͷܗ ࣜͰ΋σʔλΛૹ৴Մೳ 5VNCMS"1*

    •Ϧιʔεඥ෇͖ܗࣜϑΝΠϧΞοϓϩʔυ •multipart/form-data ͰσʔλΛૹ৴͢Δ UBC"1* IUUQTXXXUVNCMSDPNEPDTFOBQJW IUUQUPODIJEPUHJUIVCJPUBCBQJEPDTBQJJUFNDSFBUF@OFX@JUFNIUNM
  17. ·ͱΊ

  18. CONFIDENCIAL •ϑΝΠϧͷૹ৴ํ๏ͱอଘํ๏ʹ͸ҎԼͷύλʔ ϯ͕͋Δ •API ͷੑ࣭΍ϑΝΠϧͷ༻్ʹԠͯ͡ɺ͜ΕΒΛ ద੾ʹ૊Έ߹ΘͤΔͷ͕ྑ͍ ૹ৴ NVMUJQBSUGPSNEBUB #BTF อଘ

    Ϧιʔεඥ෇͚ ൚༻ϑΝΠϧΞοϓϩʔυ
  19. ΤϯδχΞืूͯ͠·͢ ࠙਌ձͰ͓࿩͠·͠ΐ͏ʂCFFST w3VCZPO3BJMT w#޲͚4BB4 wݹͯ͘ڊେͳ੍౓Λ)BDL͍ͨ͠