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
350
まだ見ぬAPIに思いを馳せて
sixeight
0
120
復習OptionSet
sixeight
0
240
今年読んだまんが
sixeight
0
210
べんりな検索ワード
sixeight
0
220
Readable Width in action
sixeight
0
160
UIPreviewInteraction: Overview
sixeight
1
590
Accessing the Music Library
sixeight
1
2.6k
Other Decks in Technology
See All in Technology
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
SSMRunbook作成の勘所_20241120
koichiotomo
2
150
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
110
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
140
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
9
1k
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
327
38k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
890
Writing Fast Ruby
sferik
627
61k
Six Lessons from altMBA
skipperchong
27
3.5k
BBQ
matthewcrist
85
9.3k
Teambox: Starting and Learning
jrom
133
8.8k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Gamification - CAS2011
davidbonilla
80
5k
A better future with KSS
kneath
238
17k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
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 ·ͱΊ ▸ ͑ͳ͍ ▸ ϓϩδΣΫτຖʹߟ͑Δඞཁ͕͋Δ ▸ ͱʹ͔͘໎͏ ▸ ձ͠·͠ΐ͏
ϝϦʔΫϦε Ϛε