Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
WebAPI の設計
Search
ゆるゆる
December 04, 2021
Programming
0
82
WebAPI の設計
2021-12-04、2022-03-18の1DayインターンでLTした内容です
ゆるゆる
December 04, 2021
Tweet
Share
More Decks by ゆるゆる
See All by ゆるゆる
改行には気をつけよう
sunyryr
0
25
Docker bake(とCache)でCI/CDを改善する
sunyryr
0
250
OpenAPI×LaravelでAPI開発を格段に便利にする方法
sunyryr
0
960
OpenAPIことはじめ
sunyryr
0
110
server side swift - codable
sunyryr
0
220
iOSアプリだけじゃないSwift
sunyryr
0
130
Other Decks in Programming
See All in Programming
Outline View in SwiftUI
1024jp
1
290
macOS でできる リアルタイム動画像処理
biacco42
9
2.3k
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
130
Java ジェネリクス入門 2024
nagise
0
690
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.8k
Ethereum_.pdf
nekomatu
0
380
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
490
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
110
僕がつくった48個のWebサービス達
yusukebe
20
17k
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
490
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
160
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
790
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Six Lessons from altMBA
skipperchong
27
3.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
RailsConf 2023
tenderlove
29
890
How to Ace a Technical Interview
jacobian
276
23k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Agile that works and the tools we love
rasmusluckow
327
21k
Embracing the Ebb and Flow
colly
84
4.5k
Navigating Team Friction
lara
183
14k
Transcript
WebAPIͷઃܭ Yumemi 1DayΠϯλʔϯ 2022/03/18 @sun-yryr / גࣜձࣾΏΊΈ
ΏΔΏΔ / Taiyo Minagawa w גࣜձࣾΏΊΈ৽ଔೖࣾ w 4FSWFSTJEF&OHJOFFSͬͯ·͢ɻ ܦྺ ͖ͳ͜ͱ
w 4XJGU 4FSWFSTJEF $*$% w 75VCFS sun-yryr taittide taittide sunyryr
ࢀߟਤॻ λΠτϧ: Web API: The Good Parts ൃߦ: O'Reilly
Ձ֨: ཧຊ ¥2420 ిࢠຊ ¥1936
࣍ • ඒ͍͠WebAPI • URLઃܭͷϙΠϯτ • WebAPIઃܭͷํ • Q&A
ඒ͍͠WebAPI
WebAPI • API => Application Programming Interface • HTTPϓϩτίϧΛͬͯ֎෦ϦιʔεͷػೳΛݺͼग़͢ •
ؔͷΑ͏ͳͷ
“ඒ͍͠”ʁ • ୭ʹͱ͍͍ͬͯ͢͜ͱ • มߋ͍͢͜͠ͱ • ੬ऑੑʹରͯ͠ؤڧͰ͋Δ͜ͱ • ஏ͔ͣ͘͠ͳ͍͜ͱ
ඒ͍͠WebAPIΛ࡞ΔͨΊʹେͳ͜ͱ • RFCͳͲͷ༷͕͋Δ߹ͦΕʹै͏͜ͱ • ༷͕ͳ͍߹σϑΝΫτελϯμʔυʹै͏͜ͱ • ଞͷ༗໊APIΛࢀߟʹ͢Δ
URLઃܭͷϙΠϯτ
• ͍ • ਓ͕ؒಡΜͰཧղͰ͖Δ • খจࣈͷΈ • αʔόʔͷ࣮ʹґଘͯ͠ͳ͍ • ߏ͕౷Ұ͞Ε͍ͯΔ
• HTTPϝιου͕نఆʹԊ͍ͬͯΔ
• ͍ • ਓ͕ؒಡΜͰཧղͰ͖Δ • খจࣈͷΈ • αʔόʔͷ࣮ʹґଘͯ͠ͳ͍ • ߏ͕౷Ұ͞Ε͍ͯΔ
• HTTPϝιου͕نఆʹԊ͍ͬͯΔ
͍URL • ೖྗ͘͢͠ɺ͍֮͑͢ͷͰྑ͍ × http://api.example.com/api/v1/users/ " api͕υϝΠϯ෦ͱύε෦Ͱඃ͍ͬͯΔ ◦ http://api.example.com/v1/users/
• ͍ • ਓ͕ؒಡΜͰཧղͰ͖Δ • খจࣈͷΈ • αʔόʔͷ࣮ʹґଘͯ͠ͳ͍ • ߏ͕౷Ұ͞Ε͍ͯΔ
• HTTPϝιου͕نఆʹԊ͍ͬͯΔ
ਓ͕ؒཧղͰ͖ΔURL • ਪଌ͍͢͠ɺԿ͕ى͜Δ͔͔Γ͍͢ • ຊޠͳͲΤϯίʔυ͞Εͯ͠·͍͔ΓͮΒ͘ͳΔͨΊɺ ආ͚ͨํ͕ྑ͍ × http://api.example.com/u/d/ "
udҙຯ͕Θ͔Βͳ͍ɻ͚Ε͍΄Ͳྑ͍Θ͚Ͱͳ͍ɻ ◦ http://api.example.com/users/detail/
• ͍ • ਓ͕ؒಡΜͰཧղͰ͖Δ • খจࣈͷΈ • αʔόʔͷ࣮ʹґଘͯ͠ͳ͍ • ߏ͕౷Ұ͞Ε͍ͯΔ
• HTTPϝιου͕نఆʹԊ͍ͬͯΔ
খจࣈͷΈͷURL • େจࣈ͕ࠞࡏ͢ΔͱΘ͔ΓͮΒ͘ͳΔ • ϗετ෦େจࣈ͕ແࢹ͞ΕΔ༷͕͋ΔͨΊɺͦΕʹै͏ × http://api.example.com/Users/Detail " ϑΥϯτʹΑͬͯେจࣈখจࣈ͕Θ͔ΓͮΒ͍ɻಛʹIͱlͳͲ
◦ http://api.example.com/users/detail/
• ͍ • ਓ͕ؒಡΜͰཧղͰ͖Δ • খจࣈͷΈ • αʔόʔͷ࣮ʹґଘͯ͠ͳ͍ • ߏ͕౷Ұ͞Ε͍ͯΔ
• HTTPϝιου͕نఆʹԊ͍ͬͯΔ
αʔόʔͷ࣮ʹґଘͯ͠ͳ͍URL • ෦࣮ΒΕͳ͍ํ͕ηΩϡϦςΟతʹ˓ × http://api.example.com/cgi-bin/users.php " CGI൛ͷPHPͬΆ͍ͳͱΘ͔ͬͯ͠·͏ ◦ http://api.example.com/users/
• ͍ • ਓ͕ؒಡΜͰཧղͰ͖Δ • খจࣈͷΈ • αʔόʔͷ࣮ʹґଘͯ͠ͳ͍ • ߏ͕౷Ұ͞Ε͍ͯΔ
• HTTPϝιου͕نఆʹԊ͍ͬͯΔ
ߏ͕౷Ұ͞Ε͍ͯΔURL • ౷Ұ͞Ε͍ͯΔͱ͔Γ͢͞ʹͭͳ͕Δ × http://api.example.com/users/123/ Ϣʔβʔใৄࡉ × http://api.example.com/users/friends?user_id=123 ࢦఆͨ͠Ϣʔβʔͷ༑ୡҰཡ
" ্ύεύϥϝʔλͰɺԼΫΤϦύϥϝʔλͱҰ؏ੑ͕ͳ͍ ◦ http://api.example.com/users/123/ ◦ http://api.example.com/users/123/friends/
• ͍ • ਓ͕ؒಡΜͰཧղͰ͖Δ • খจࣈͷΈ • αʔόʔͷ࣮ʹґଘͯ͠ͳ͍ • URLߏ͕౷Ұ͞Ε͍ͯΔ
• HTTPϝιου͕نఆʹԊ͍ͬͯΔ
HTTPϝιου͕نఆʹԊ͍ͬͯΔ • ༷ʹै͏ • GETͰߋ৽͠ͳ͍ͳͲ (&5 ใΛऔಘ͢Δ 1045 ৽͍͠ใΛొ͢Δ
165 ࢦఆͨ͠63-ʹใΛొ͢Δ ใΛ্ॻ͖͢Δ 1"5$) 165ʹࣅ͍ͯΔ ใͷҰ෦Λߋ৽͢Δ %&-&5& ࢦఆͨ͠ใΛআ͢Δ
WebAPIઃܭͷਐΊํ
1. ػೳͷҰཡΛ࡞͢ΔʢϢʔεέʔεͷ࡞ʣ 2. Ϣʔεέʔε͝ͱʹඞཁͳAPIΛߟ͑Δ 3. 2Ͱߟ͑ͨඞཁͳAPIʹରͯ͠ɺHTTP Method, URL, ϦΫΤε τͷཁૉϨεϙϯεΛܾΊ͍ͯ͘
Q&A
໊ࢺ୯ܥʁෳܗʁ • αʔϏεʹΑͬͯ୯ͩͬͨΓෳͩͬͨΓ͢Δ • جຊతʹू߹Λද͢ͷෳܗ͕దͱ͞Ε͍ͯΔ • ςʔϒϧ໊େମෳܗͳͷͰἧ͑Δͱ͔Γ͔ͬͨ͢Γ ͢Δ ʢ˞ςʔϒϧͱશ͘ಉ͡ΤϯυϙΠϯτΛ༻ҙ͢Δ͚ͩ✖ʣ
ಈࢺͬͯμϝʁ • ઈରͰͳ͍ • searchͳͲͷಈࢺΛ͍ͬͯΔαʔϏε͋Δ • ͨͩɺHTTPMethodͰදͤΔ”GET”ͳͲΘͳ͍ํ͕ྑ͍
୯ޠͷ࿈݁ʮ-ʯʁʮ_ʯʁ • ͲͪΒ͔ยํͰ౷Ұ͢Εྑ͍ • SEOతʹϋΠϑϯͷํ͕ྑ͍͕ɺWebAPIʹؔͳ͍ • ΞϯμʔόʔϦϯΫදهͷԼઢͱඃΔ͜ͱ͕͋ΔͷͰɺϋΠ ϑϯΛ͓͢͢Ί͍ͨ͠
ΫΤϦͱύεͷ͍͚ • URLϦιʔεΛද͢ͷͰ͋ΔͨΊɺҰҙʹܾ·ΔͷͰ͋ ΕύεʹؚΊͨํ͕ྑ͍ʢྫ: ϢʔβʔIDʣ • লུͰ͖ΔͷΫΤϦʹ͢Δͱྑ͍ʢྫ: ҰཡऔಘͷߜΓࠐ Έ݅ʣ
ඞͣ൚༻తʹ͢Δඞཁͳ͍ • ͘ެ։ͤͣɺࣗΒͰดͨ͡APIͷ߹൚༻తʹ͢Δ͜ͱͰ ͔͍͑ͬͯͮΒ͘ʢ=Ԛ͘ʣͳͬͯ͠·͏͜ͱ͕͋Δ • ྫ͑ɺτοϓϖʔδʹඞཁͳͯ͢ͷใΛ1ʹฦ͢APIΛ ࡞͍͍ͬͯ • ϢʔεέʔεΛେࣄʹͯ͠ઃܭ͍ͯ͘͠ͱྑ͍
OpenAPIʹ͍ͭͯগ͠
OpenAPI / Swaggerͱ • REST APIͷهड़ϑΥʔϚοτ • yaml or jsonͰهड़Ͱ͖Δ
• όʔδϣϯ2·ͰSwaggerͱݺΕ͍͕ͯͨɺݱࡏOpenAPI ͱݺΕ͍ͯΔ • ݱࡏόʔδϣϯ3
͕ࣗਪͤΔઃܭΛࢦͯ͠ ؤு͍ͬͯͩ͘͞