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

OpenAPIを中心に考えるAPI開発入門 / Introduction to API Dev...

OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI

Postman API Night Fukuoka 2024 Spring
https://postman.connpass.com/event/309419/

shiro seike

April 16, 2024
Tweet

More Decks by shiro seike

Other Decks in Programming

Transcript

  1. ©Fusic Co., Ltd. 2 ਗ਼Ո ࢙࿠ @seike460 AWS Community Builder

    Serverless - ίϛϡχςΟ - Fukuoka.php - Fukuoka.go - JAWS-UG Fukuoka - Serverless Meetup Fukuoka - Cloudflare Meetup Fukuoka - JP_Stripes Fukuoka ࣗݾ঺հ ͸͡Ίʹ גࣜձࣾFusic ϓϦϯγύϧΤϯδχΞ/ΤόϯδΣϦετ
  2. ©Fusic Co., Ltd. 3 CONTENTS ໨࣍ 1. OpenAPIͱ͸ 2. OpenAPIಋೖͷ͖͔͚ͬ

    3. OpenAPI GeneratorʹΑΔίʔυࣗಈੜ੒ 4. PostmanΛར༻ͨ͠RequestͱMock 5. ·ͱΊ
  3. ©Fusic Co., Ltd. 5 OpenAPIͱ͸ - RESTful API࢓༷Λهड़͢ΔͨΊͷۀքඪ४ - ※ݱࡏ͸v3ͰͦΖͦΖv4ϦϦʔε༧ఆ

    - ݩʑ͸Swagger (v2)ͱͯ͠஌ΒΕ͍ͯͨ - JSON·ͨ͸YAMLͰAPIͷΤϯυϙΠϯτͱૢ࡞Λఆٛ
  4. ©Fusic Co., Ltd. 8 OpenAPI ಋೖͷ͖͔͚ͬ - ϊΠΤετ߹ಉձ༷ࣾͷެ։ࣄྫ - https://fusic.co.jp/works/47

    - ҩֶݚڀ༻ͷಠࣗͷಛघ೴೾ղੳͷࣗಈԽ - ݚڀऀ༷͔Βͷղੳґཔʹରͯ͠ खಈղੳΛߦ͍ϨϙʔτఏڙΛߦ͍ͬͯͨ - ͜ͷղੳΛࣗಈԽ͢ΔߏஙΛߦͬͨ - ϑϧαʔόʔϨε x SaaSͱ͍͏ࣄྫ
  5. ©Fusic Co., Ltd. 9 ଘࡏͨ͠՝୊ Լه։ൃΛߦ͏ඞཁ͕͋ͬͨ - ReactͷϑϩϯτΤϯυ - PHP

    LaravelͷόοΫΤϯυAPI ୹ظؒͰߏஙΛ׬ྃ͢Δඞཁ͕͋Γ ϑϩϯτΤϯυͱόοΫΤϯυΛ෼ׂͯ͠ ಉ࣌ฒߦͰ։ൃΛߦͬͨ APIͷ࢓༷Λ࿈ܞ͢Δඞཁ͕͋Δ
  6. ©Fusic Co., Ltd. 10 OpenAPI Generator ͦ͜Ͱڞ௨ͷAPIͷ࢓༷Λڞ༗͠ͳ͕Β ͞Βʹίʔυੜ੒͕ग़དྷΔ OpenAPI GeneratorΛར༻ͨ͠

    ίʔυੜ੒Λલఏͱͨ͠։ൃΛ࣮ࢪ API࢓༷ͷमਖ਼͕ൃੜͨ࣌͠΋ɺ APIΠϯλʔϑΣʔε͸ଈࠩ͠ସ͑Մೳʹ
  7. ©Fusic Co., Ltd. 12 OpenAPI v3ͷجຊߏ଄ͱهड़ํ๏ - OpenAPI Object -

    ϧʔτυΩϡϝϯτ - Info Object - APIͷجຊ৘ใ - Servers Object - αʔό৘ใͱ؀ڥ - Paths Object - ར༻Մೳͳύεͱૢ࡞ - Components Object - ࠶ར༻ՄೳͳεΩʔϚɺύϥϝʔλʔ
  8. ©Fusic Co., Ltd. 13 OpenAPI v3ͷجຊߏ଄ͱهड़ํ๏ - OpenAPI Object -

    ϧʔτυΩϡϝϯτ - Info Object - APIͷجຊ৘ใ - Servers Object - αʔό৘ใͱ؀ڥ - Paths Object - ར༻Մೳͳύεͱૢ࡞ - Components Object - ࠶ར༻ՄೳͳεΩʔϚɺύϥϝʔλʔ
  9. ©Fusic Co., Ltd. 14 OpenAPI v3ͷجຊߏ଄ͱهड़ํ๏ - OpenAPI Object -

    ϧʔτυΩϡϝϯτ - Info Object - APIͷجຊ৘ใ - Servers Object - αʔό৘ใͱ؀ڥ - Paths Object - ར༻Մೳͳύεͱૢ࡞ - Components Object - ࠶ར༻ՄೳͳεΩʔϚɺύϥϝʔλʔ
  10. ©Fusic Co., Ltd. 15 OpenAPI v3ͷجຊߏ଄ͱهड़ํ๏ - OpenAPI Object -

    ϧʔτυΩϡϝϯτ - Info Object - APIͷجຊ৘ใ - Servers Object - αʔό৘ใͱ؀ڥ - Paths Object - ར༻Մೳͳύεͱૢ࡞ - Components Object - ࠶ར༻ՄೳͳεΩʔϚɺύϥϝʔλʔ
  11. ©Fusic Co., Ltd. 16 OpenAPI v3ͷجຊߏ଄ͱهड़ํ๏ - OpenAPI Object -

    ϧʔτυΩϡϝϯτ - Info Object - APIͷجຊ৘ใ - Servers Object - αʔό৘ใͱ؀ڥ - Paths Object - ར༻Մೳͳύεͱૢ࡞ - Components Object - ࠶ར༻ՄೳͳεΩʔϚɺύϥϝʔλʔ
  12. ©Fusic Co., Ltd. 19 OpenAPI React Query Codegen Fusicࣾһͷ @7nohe͕ެ։͍ͯ͠Δ

    OSSΛར༻͠TanStack QueryΛੜ੒ (چ React Query) Client෦෼ͷϦΫΤετ෦෼΋ ׬શʹҠৡ͠·ͨ͠
  13. ©Fusic Co., Ltd. 20 OpenAPI React Query Codegen Fusicࣾһͷ @7nohe͕ެ։͍ͯ͠Δ

    OSSΛར༻͠TanStack QueryΛੜ੒ (چ React Query) Client෦෼ͷϦΫΤετ෦෼΋ ׬શʹҠৡ͠·ͨ͠
  14. ©Fusic Co., Ltd. 23 PHPɿPostmanʹΑΔϦΫΤετͷੜ੒ PHP͸։ൃதʹϦΫΤετΛड͚͍ͨ - React͸։ൃதͳͷͰૹ৴ग़དྷͳ͍ - Import

    - OpenAPIͷYamlΛಡΈࠐ·ͤΔ - Request͕࣮ࡍʹ࣮ߦͰ͖Δ ։ൃΛ؆୯ʹՃ଎ͤ͞Δࣄ͕Մೳʹʂ
  15. ©Fusic Co., Ltd. 24 ReactɿPostmanʹΑΔmock server…Λར༻͔ͨͬͨ͠ React͸։ൃதʹϨεϙϯεΛड͚͍ͨ - PHP͸։ൃதͳͷͰड৴ग़དྷͳ͍ ʢ౰࣌ษڧෆ଍Ͱ஌Βͳ͔ͬͨ…ʣ

    ఆٛΛݩʹMock ServerΛཱͯΕΔͷͰ PostmanͰ૬ޓͷ΍ΓऔΓΛ׬݁Մೳ ʢ࣮ࡍ͸Swagger EditorͰ ɹMock ServerΛੜ੒͍ͯͨ͠ʣ
  16. ©Fusic Co., Ltd. 25 ReactɿPostmanʹΑΔmock server…Λར༻͔ͨͬͨ͠ React͸։ൃதʹϨεϙϯεΛड͚͍ͨ - PHP͸։ൃதͳͷͰड৴ग़དྷͳ͍ ʢ౰࣌ษڧෆ଍Ͱ஌Βͳ͔ͬͨ…ʣ

    ఆٛΛݩʹMock ServerΛཱͯΕΔͷͰ PostmanͰ૬ޓͷ΍ΓऔΓΛ׬݁Մೳ ʢ࣮ࡍ͸Swagger EditorͰ ɹMock ServerΛੜ੒͍ͯͨ͠ʣ
  17. ©Fusic Co., Ltd. 28 ·ͱΊ RESTful API࢓༷Λهड़͢ΔͨΊͷۀքඪ४ͱͯ͠ͷOpen APIͱ͍͏࢓༷͕͋Δ Point 01

    Yaml·ͨ͸JsonͰઃܭՄೳͳͷͰΤϯδχΞϑϨϯυϦʔͳOpenAPI Tools Point 02 ࠓճͷࣄྫͰ͸PHPͱReactʹͯίʔυੜ੒͢Δ͜ͱͰυϝΠϯ෦෼͚ͩͷ։ൃʹूத Point 03 PostmanΛར༻͢Δ͜ͱͰ͞ΒͳΔޮ཰ԽΛ͸͔Δࣄ͕Մೳʹɺલఏ஌͕ࣝඞཁͳͷͰ͔ͬ͠Γֶश͕ඞཁʂ Point 04