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
390
Web APIについての雑談
よく悩むところを列挙しました
Tomohiro Nishimura
December 23, 2015
Tweet
Share
More Decks by Tomohiro Nishimura
See All by Tomohiro Nishimura
レガシーシステム洗い出し大作戦
sixeight
0
1.4k
我々のRealmはどこからやってくるのか
sixeight
1
340
まだ見ぬAPIに思いを馳せて
sixeight
0
110
復習OptionSet
sixeight
0
230
今年読んだまんが
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
言葉は感情の近似値である。その感情と言葉の誤差を最小化しよう ~コミュニケーションにおけるアナログ/デジタル変換の課題に立ち向かう~
nktamago
0
250
グイグイ系QAマネージャーの仕事
sadonosake
0
360
LLVM/ASMを使った有限体の高速実装
herumi
0
120
とあるOSSを継続可能にするための取り組みについて / OSS Refactoring Process
bun913
1
220
AIで変わるテスト自動化:最新ツールの多様なアプローチ/ 20240910 Takahiro Kaneyama
shift_evolve
0
250
アプリをリリースできる状態に保ったまま 段階的にリファクタリングするための 戦略と戦術 / Strategies and tactics for incremental refactoring
yanzm
6
1.5k
Technical Writing Meetup vol.35
soracom
PRO
2
130
o1のAPIで実験してみたが 制限きつすぎて辛かった話
pharma_x_tech
0
230
DroidKaigi 2024 たすけて!ViewModel
mhidaka
5
1.1k
JEP 480: Structured Concurrency
aya_ebata
0
130
再考 アクターモデル/ reconsider actor model
ytake
0
380
Classmethod AI Talks(CATs) #1 司会進行スライド(2024.09.19) / classmethod-ai-talks-aka-cats_moderator-slides_vol1_2024-09-19
shinyaa31
0
240
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
325
38k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
109
6.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
0
130
Navigating Team Friction
lara
183
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
36
2.1k
Agile that works and the tools we love
rasmusluckow
327
20k
Intergalactic Javascript Robots from Outer Space
tanoku
268
26k
Scaling GitHub
holman
458
140k
The Invisible Customer
myddelton
119
13k
The Illustrated Children's Guide to Kubernetes
chrisshort
47
48k
Docker and Python
trallard
39
3k
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 ·ͱΊ ▸ ͑ͳ͍ ▸ ϓϩδΣΫτຖʹߟ͑Δඞཁ͕͋Δ ▸ ͱʹ͔͘໎͏ ▸ ձ͠·͠ΐ͏
ϝϦʔΫϦε Ϛε