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
Web APIについての雑談
Search
Tomohiro Nishimura
December 23, 2015
Technology
0
400
Web APIについての雑談
よく悩むところを列挙しました
Tomohiro Nishimura
December 23, 2015
Tweet
Share
More Decks by Tomohiro Nishimura
See All by Tomohiro Nishimura
レガシーシステム洗い出し大作戦
sixeight
0
1.5k
我々のRealmはどこからやってくるのか
sixeight
1
360
まだ見ぬAPIに思いを馳せて
sixeight
0
120
復習OptionSet
sixeight
0
240
今年読んだまんが
sixeight
0
220
べんりな検索ワード
sixeight
0
230
Readable Width in action
sixeight
0
160
UIPreviewInteraction: Overview
sixeight
1
600
Accessing the Music Library
sixeight
1
2.6k
Other Decks in Technology
See All in Technology
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
260
podman_update_2024-12
orimanabu
1
270
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
450
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
380
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
Storage Browser for Amazon S3
miu_crescent
1
140
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
150
Jetpack Composeで始めるServer Cache State
ogaclejapan
2
170
.NET 9 のパフォーマンス改善
nenonaninu
0
850
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
137
6.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
GitHub's CSS Performance
jonrohan
1030
460k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Mobile First: as difficult as doing things right
swwweet
222
9k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
KATA
mclloyd
29
14k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Why Our Code Smells
bkeepers
PRO
335
57k
Writing Fast Ruby
sferik
628
61k
Transcript
Web API ʹ͍ͭͯͷࡶஊ ؔϞό #9
ג ͯͳ 8FCΞϓϦέʔγϣϯΤϯδχΞ εϚʔτϑΥϯΞϓϦΤϯδχΞ ͲΕத్ͰযΔ ޚࡏॴַΑ͔ͬͨ id:Sixeight (@tomohi_ro)
Web API ΣϒΤʔϐʔΞΠ
ؔϞό#9 Web API ͱͳΜͧ )551ϓϩτίϧΛར༻ͯ͠ωοτϫʔ Ϋӽ͠ʹݺͼग़͢"1* 8FC"1*5IF(PPE1BSUT
εϚʔτϑΥϯΞϓϦ ͱ Web API
͑ͳ͍
ؔϞό#9 LSUDs ͱSSKDs ▸ LSUDs (large set of unknown developers)
▸ ͘Ұൠతʹެ։͞Ε͍ͯΔ ▸ Twitter/Facebook/Instagram/ Google/etc ▸ SSKDs (small set of known developers) ▸ ݶΒΕͨൣғʹެ։͞Ε͍ͯΔ ▸ ࣗࣾΞϓϦͳͲ
44,%T গͷ͍ͬͯΔ։ൃऀ͚
ؔϞό#9 SSKDs (small set of known developers) ▸ ఆ͞Ε͍ͨํ͔͠͞Εͳ͍ ▸
ΞϓϦʹ࠷దԽͨ͠ܗͰఏڙͰ͖Δ ▸ ։ൃऀಉ࢜ͰձͰ͖Δ ▸ ີ݁߹͕ͪ͠ ▸ ଥڠ͕ͪ͠
ίʔϧ 1εΫϦʔϯɺ
ؔϞό#9 1εΫϦʔϯɺ1ίʔϧ ▸ 1ը໘Λදࣔ͢ΔͷʹɺWeb APIͷݺͼग़͠Ұճʹ͓͍͑ͨ͞ ▸ جຊతʹෳͷϦιʔε͕ඞཁ ▸ αʔόʔଆͷ࣮ෳࡶʹͳΔ ▸
ͲΜͲΜRESTͷߟ͑ํ͔ΒͦΕΔ ▸ ҙਂ͘ઃܭ͢ΕՄೳ ▸ ը໘Λத৺ʹߟ͑͗͢Δͱมߋʹऑ͘ͳΔ
ΤϯυϙΠϯτ APIͷإ
ؔϞό#9 ΤϯυϙΠϯτ ▸ SSKDsͩͱΤϯυϙΠϯτͳΜͰ͍͍ͱ͍͏ ▸ ϝϯςφϯεੑ ▸ ݟͨѱ͍ͱΔؾʹӨڹ͢Δ ▸ ෳܥͳͷ͔୯ܗͳͷ͔
▸ HATEOASΈ͍ͨͳͷਅ໘ʹߟ͑ͯྑͦ͞͏
3&45 Ԟ͞Μʹઆ໌͠ΖͱݴΘΕ͍ͯ͠ see also: http://www.geocities.jp/yamamotoyohei/rest/rest-to-my-wife.htm
ؔϞό#9 REST ▸ ͜͜ͰϑΟʔϧσΟϯάͬΆ͍ ▸ 1εΫϦʔϯɺ1ίʔϧͱ૬ੑѱ͍ؾ͕͢Δ ▸ ϩάΞτ DELETE ͳͷ͔Ͳ͏͔
▸ λΠτϧͷߋ৽ PATCHʁʁʁʁʁʁ ▸ ૢ࡞͕ႈͳΒ PUT/DELETEɺͦ͏͡Όͳ͚ΕPOST
Ϩεϙϯε ҙ֎ͱ໎͏
ؔϞό#9 Ϩεϙϯε ▸ ϦιʔεΛߋ৽ͨ͠ͱ͖ͷϨεϙϯεɺߋ৽લʁͦΕͱߋ৽ޙʁ ▸ ϦιʔεΛফͨ͠ͱ͖204? ▸ 200͚ͩΕͲϨεϙϯεཁΒͳ͍ͱ͖ʁ ▸ {“success”:
true} vs {} vs ۭจࣈྻ (←͜Εͳ͍) ▸ ྻΛฦ͢ͱ͖ʹΦϒδΣΫτʹ͢Δ͔Ͳ͏͔ ▸ ͜ΕηΩϡϦςΟͷ͕͋ΔͷͰΦϒδΣΫτͰ ▸ ඞཁͳཁૉ͚ͩʁ֦ுੑΛߟ͑ͯଟΊʹΒ͓ͬͯ͘ʁ ▸ {“user”: { id: 1, name: “hoge”}} vs {“user_id”: 1, “user_name”: “hoge”} ▸ ͷϑΥʔϚοτͲ͏͢Δͷ͔ ▸ ϖʔδϯάͲ͏͢Δͷ͔ ▸ JSONͳͷ͔ଞͷϑΥʔϚοτͳͷ͔
ΤϥʔϨεϙϯε ࣮ॏཁ
ؔϞό#9 ΤϥʔϨεϙϯε ▸ ϑΥʔϚοτݻఆ͍ͨ͠ ▸ ϝοηʔδΛ;͘ΊΔ vs ΞϓϦͰੜ ▸ ଟݴޠԽͲ͏͢Δ͔ɺߋ৽͢͠͞Ͳ͏͔
▸ ΞϓϦଆͰΤϥʔʹର͢ΔέΞ͕ͻͭΑ͏͕Ͳ͏͔ ▸ Τϥʔίʔυඞཁͳͷ͔ ▸ Ͳ͜·Ͱใ͕͍Δͷ͔
ೝূ ࣗͰ͋Δ͜ͱͷূ໌
ؔϞό#9 ೝূ ▸ APIτʔΫϯΈ͍ͨͳͷ༻ҙ͢Δ ▸ Expireͱ͔ϦϑϨογϡͷΈ͕͍Δ ▸ ΕͨΒࠔΔ ▸ ܦ࿏͕҉߸Խ͞Ε͍ͯͨΒ·͍͍͋
▸ OAuth 2.0 ▸ ͏·͘Δํ๏͋Γͦ͏͚ͩΕͲݟͳ͠
҉߸Խ ಡԽ Ӆ͍ͨ͠ͷͰ
ؔϞό#9 ҉߸Խ,ಡԽ ▸ Ӆ͍ͨ͠ใΛӅ͢ ▸ ୈࡾऀʹରͯ͠(ݸਓใ)ɺ༻ऀʹରͯ͠ (ήʔϜͱ͔) ▸ HTTPSͩͱ͍͍ͩͨ҆৺ ▸
༰ΛಡԽͯ͠όΠφϦͰૹΔͱ͔ ▸ ΞϓϦଆͰσίʔυ͢Δͷେม ▸ σίϯύΠϧ͞Εͨͱ͖ͷରࡦ ▸ ૬खCIA͡Όͳͯ͘ૉਓ
όʔδϣϯ ޙํޓͷཁ
ؔϞό#9 όʔδϣϯ ▸ ޙํޓੑΛอ͍ͪͨ ▸ όʔδϣϯΛࢦఆ͢Δ͜ͱͰϨεϙϯεΛฦ͠Θ͚Δ ▸ /v1/hoge/piyo, ?version=1, X-API-Version:
1, application/ vnd.example.v1+json ▸ Ͳ͏ͬͯཧ͢Δ͔ ▸ ผͷϑΝΠϧͰཧ͢Δ ▸ ifจͰذ͢Δ ▸ ݹ͍όʔδϣϯΛ͍ͭഇࢭ͢Δ͔
ඇޓͳมߋ ආ͚ΒΕͳ͍
ؔϞό#9 ඇޓͳมߋ ▸ ਃͲ͏͢Δͷ͔ ▸ ਃ༻ͷαʔόʔΛ༻ҙͯͦͪ͠Βʹ͚Δ ▸ ΤϯυϙΠϯτΛฦ͢API (HATEOASʹͭͳ͕Δ) ▸
ਃ࣌ͷΈຊ൪ͱผͷͷݟͤΔͷͲ͏ͳͷ͔ ▸ ͪͳΈʹͯͳͰͬͯͳ͍ ▸ ڧ੍όʔδϣϯΞοϓ ▸ ΞϓϦͷόʔδϣϯΛ্͛ͳ͍ͱ͑ͳ͘͢Δ
ͦͷଞͷ
ؔϞό#9 ▸ υΩϡϝϯτ ▸ ςετ ▸ ΦʔέεϨʔγϣϯ ▸ ཉ͍͚ͩ͠Β͏ͱ͔
▸ ࣗಈੜ ▸ Swaggerͱ͔ ▸ ແݶʹ͋Δ
·ͱΊ ͦͯ͠
ؔϞό#9 ·ͱΊ ▸ ͑ͳ͍ ▸ ϓϩδΣΫτຖʹߟ͑Δඞཁ͕͋Δ ▸ ͱʹ͔͘໎͏ ▸ ձ͠·͠ΐ͏
ϝϦʔΫϦε Ϛε