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
API になろう / Let's become an API
Search
Pちゃん
December 18, 2019
Programming
0
3.2k
API になろう / Let's become an API
Pちゃん
December 18, 2019
Tweet
Share
More Decks by Pちゃん
See All by Pちゃん
天下一 Dev Server 武道会 / World Dev Server Tournament
p1ch_jp
2
860
この先生きのこるためのPostCSS実践入門
p1ch_jp
1
1.5k
エンジニアのためのデザインの話
p1ch_jp
0
910
Other Decks in Programming
See All in Programming
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
EventSourcingの理想と現実
wenas
6
2.3k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
CSC509 Lecture 09
javiergs
PRO
0
140
Jakarta EE meets AI
ivargrimstad
0
120
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
310
Remix on Hono on Cloudflare Workers
yusukebe
1
280
最新TCAキャッチアップ
0si43
0
140
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
イベント駆動で成長して委員会
happymana
1
320
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
427
64k
Code Reviewing Like a Champion
maltzj
520
39k
Typedesign – Prime Four
hannesfritz
40
2.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
BBQ
matthewcrist
85
9.3k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
A better future with KSS
kneath
238
17k
Raft: Consensus for Rubyists
vanstee
136
6.6k
It's Worth the Effort
3n
183
27k
Why Our Code Smells
bkeepers
PRO
334
57k
Building Adaptive Systems
keathley
38
2.3k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Transcript
өͬͨΒ͢
͜ΜΜ
PͪΌΜ @p1ch_jp
͓·͑ͩΕ w ॴଐ w גࣜձࣾσΟʔɾΤψɾΤʔ w Կͯ͠Δ w ϑϩϯτΤϯυΤϯδχΞ
͍
ࠓͳΜͰ͕͢
-5ότϧͱ͍͏͜ͱͰ Ժ͔͡Όͳ͍Ͱ͢Ͷ
͍
΅͕͘͜͜ʹ͍Δ ܦҢͳΜͰ͕͢
None
None
ͳΜ͔ΜͰ
͏͔ͬΓϦϯάʹ ্͕Δ͜ͱʹͳͬͯ͠·ͬͨ
͔͠ͳ͔ͥ όοΫΤϯυͰ
ϏϏͬͯ·͢
ԿΛ͢ͷ͔
ຊͷ΅͘ͷςʔϚ
όοΫΤϯυͱ ͍͏͜ͱͳΜͰ͕͢
ͨͿΜདྷͯΔਓͷ ΄ͱΜͲͷਓ͕
σβΠφʔ ϑϩϯτΤϯυΤϯδχΞ 03
ΑͶʁ
ͳʹΑΓ ΅͕ࣗ͘ৄ͘͠ͳ͍
ͱ͍͏Θ͚Ͱ
ࠓͰ͢Ͷ
࣮ͰΞϨίϨͯ͠ಘͨ ҝʹͳΔݟͷڞ༗ͱ͔
ͦ͏͍͏ͷ Ͱ͖ͯ·ͤΜ
ԿΛ͔͢ͱݴ͏ͱʜ
࠷ۙझຯͰ࡞ͬͨAPI ͷͰ ͠Α͏ͱࢥ͍·͢
גࣜձࣾσΟʔɾΤψɾΤʔσβΠϯຊ෦αʔϏεσβΠϯ෦%&(( ౻ݪ৻ଠBLB1$IBO APIʹͳΖ͏ FROKAN x UIT #2 - ΕLT ότϧ
ఆௌߨऀ
ఆௌߨऀ w ීஈɺࣄͰϑϩϯτΤϯυΛॻ͍͍ͯΔ͕ɺझຯ ݸਓ։ൃͰόοΫΤϯυॻ͍͍͖͍ͯͨਓ w มͳAPI͕ੜ͑ͯΔͷΛݟ͚ͭΔͱָ͘͠ͳͬͪΌ͏ਓ
͜͏ͳΔͱΑͦ͞͏ w ॳֶऀʹෛ୲ͷগͳ͍ٕज़ελοΫΛͬͯɺ࣮ࡍʹ (FUUJOH4UBSU͢Δػӡ͕ߴ·Δ w ͱݴ͑Կͭ͘Ε͑͑ͶΜΛղফͯ͠ɺ࣮ࡍʹ (FUUJOH4UBSU͢Δػӡ͕ߴ·Δ
Ͱ
ࠓɺग़ͯ͘ΔՌ શ෦JSONͳΜͰ
Έͳ͞Μ͓खݩʹ
1PTUNBO
ͱ͔
1PTUXPNBO
ͱ͔
*OTPNOJB
ͱ͔ى্ͪ͛ͳ͕Β ฉ͍͍͚ͯͨͩΔͱ
ָ͍͔͠͠Ε·ͤΜ
ΈΜͳ͕ى্ͪ͛ͯΔؒʹ ΅͕͘ञΛҿΉ࣌ؒ
͍
ࠓճ࡞ͬͨͷ 0
P-Chan API
IUUQTBQJQDIBOJN
ಡΜͰυϝΠϯͷ͘
΅͘ʹؔ͢Δใ͕ฦΓ·͢
GET /identification GET /accounts GET /assets PATCH /assets
༻ٕज़
͜Μͳײ͡Ͱ͢
ࠓ
ୈҰষɺίίΒΜ
ୈೋষɺίίΒΜ
ʹผ͚ͯհ͍͖ͯ͠·͢
ͱΓ·αʔόʔΛى্ͪ͛ͯ ੩తͳใΛฦͯ͠ΈΔ 1
ίίΒΜͷ
͜ͷষݴ͍͍ͨ͜ͱ ͻͱ͔ͭ͠ͳ͍
झຯor ݸਓ։ൃ && ॳΊͯͷαʔόʔαΠυNode.js
TypeScript + Express Ͱ͏
5ZQF4DSJQU &YQSFTT w &YQSFTTӫރਰͷܹ͍͠ք۾ʹ͓͍ͯ͘͠ɺރΕ ͭͭݱͰ͑ΔͷͰʢރΕͯΔͷใྔ͕๛ w 5ZQF4DSJQUϑϩϯτ·ͩ54ͱ૬ੑͷྑ͍ϑϨʔϜϫʔ Ϋͦ͏͡Όͳ͍ϑϨʔϜϫʔΫ͋Δ͕ɺόοΫΤϯυ ͍͍ͩͨ૬ੑ͍͍ɻϑϩϯτͱҧͬͯXFCQBDLͷઃఆ Ͱ͠ΜͲ͍ͱ͔ͳͯ͘ɺجຊUTDίϚϯυͰઓ͑ΔͷͰ
ྑ͞Έ͕͋Δɻ
࠷ۙNest.jsͱ͔͕ ྲྀߦͬͯ·͕͢
Ұ൪ॳΊΦʔιυοΫεʹ ExpressͰΉ͜ͱΛΦεεϝ σΟεͬͯͳ͍Αɺ510ͶʢҰԠ
P-Chan APIͷ߹ ͜ΕͰ
GET /identification
GET /accounts
͋ͨΓΛฦͯ͠·͢
͍
ͱΓ·͜ΕͰAPIΊ·ͨ͠
ͱݴ͑͜Ε͚ͩ͡Ό Կ໘ന͘Ͷ͑
όοΫΤϯυͳΒͰͷ
औ͖ͬͯͨσʔλΛ อଘͨ͠Γɺు͖ग़ͨ͠Γ
ͦ͏͍͏ͷ͍ͨ͠
σʔλΛऔ͖ͬͯͯอଘͯ͠ ు͖ग़͢·ͰͷΞϨίϨ 2
ͲΜͳΤϯυϙΠϯτ ੜ͔͢ͳʔͱࢥ͍ͬͯͨΒ
͜ΜͳIssue͕ͨͬͯͨͷͰ
ݮΔΜ͡Όͳ͍͍͍͔͠
͜ΜͳΤϯυϙΠϯτΛ ༻ҙ͠·ͨ͠
PATCH /assets GET /assets ࢿ࢈ใͷฦ٫ͱߋ৽
αϯϓϧσʔλͰ ͍͍͔ͱࢥͬͨΜͰ͕͢
໘നΈʹ͚ܽΔͷͰ
ʢϦΞϧΨνσʔλฦ͠·͢ʣ
͜ΕΒͷΤϯυϙΠϯτ ओʹ2ͭͷఔͰΓཱͬͯΔ
PuppeteerͰ σʔλΛऔͬͯ͘Δఔ Prisma FrameworkͰ σʔλΛग़͠ೖΕ͢Δఔ Prisma Framework
PuppeteerͰ σʔλΛऔͬͯ͘Δఔ Prisma FrameworkͰ σʔλΛग़͠ೖΕ͢Δఔ Prisma Framework
Puppeteer ͏ͳΒσϓϩΠઌΑ͘ߟ͑Α͏ w ZEIT Nowɺv2͔ΒFaaSతͳײ͡ʹͳͬͨͷͰɺ͋Μ ·ΓϔουϨεϒϥβΛͿΜճ͢Έ͍ͨͳέʔεΛఆ ͞Ε͍ͯͳ͍ɻλΠϜΞτ͕10 ඵɻ ՝ۚͰ5 ʹ
w ͓ͱͳ͘͠GAE/SE λΠϜΞτ60ඵ ͱ͔ɺGoogle Cloud Functions λΠϜΞτ540ඵ ͱ͔ͬͨ΄͏͕ ྑ͍ w ͨͿΜP-Chan APIɺ͖͡ʹΓ͑Δ
PuppeteerͰ σʔλΛऔͬͯ͘Δఔ Prisma FrameworkͰ σʔλΛग़͠ೖΕ͢Δఔ Prisma Framework
ࠓҰ൪ͬͯ΄͍ͭ͠
͋ͨΓ·͑ͳΜͰ͕͢
ϑϩϯτΤϯυͰͰ͖ͳ͍ όοΫΤϯυͷ໘ന͞ͱͯ͠
σʔλͷӬଓԽ͕͋Δ
2019ͷ ΞϓϦέʔγϣϯ։ൃʹ͓͍ͯ
େମͷ߹ɺORMͱ͍͏ྨͷ ϥΠϒϥϦΛ͏͜ͱʹΑͬͯ
SQLΛॻ͖͢Δ͜ͱͳ͘ ؆୯ʹDBͷCRUD͕Ͱ͖ΔΑ͏ʹ
ͱݴ͑
ॳֶऀʹͱͬͯ
ίʔυ͕ Ұ൪ΰνϟΓΨνͳ෦Ͱ͋Γ
ORMಠࣗͷϚΠάϨʔγϣϯϧʔ ϧه๏Ͱམ͕ͪ͠
ͦ͜Ͱࠓճͬͨͷ͕
Prisma Framework
ORM Migration Sequel Pro ͬΆ͍ͭ
͍ํ؆୯
εΩʔϚΛఆٛ͢Δ Prettierαϙʔτ͞ΕͯΔΑ TDIFNBQSJTNB
ϚΠάϨʔγϣϯͷੜͱ࣮ߦ prisma2 lift save && prisma2 lift up 5FSNJOBM
͜Μͳײ͡ͰՃͨ͠Γ DPOUSPMMFSTBTTFUTUT
͜Μͳײ͡Ͱfindͨ͠Γ DPOUSPMMFSTBTTFUTUT
ΊͪΌͪ͘Όײతͳ ΦϒδΣΫτͷૢ࡞Ͱ݁
·ͩ·ͩ͜Ε͔ΒͳORM͚ͩͲɺ ৮ͬͨײ͡ɺखʹೃછΉؾ͕͢Δ
ҰԠTypeScript ORMքͷԦऀ TypeORMͱͷൺֱ
vs TypeORM (1/2) w ޙൃͷͨΊɺશମతʹ·ͩ·ͩউͯͳ͍ʢػೳͷଟ͞ɺ ରԠ͢Δσʔλϕʔεͷଟ͞ɺ࣮ࡍͷར༻ྫͳͲͳͲʣ w ͱݴ͑ɺ๏ਓ͕։ൃମͳͷͰɺ։ൃεϐʔυ͕҆ఆ ͍ͯ͠Δʢ࠷ͰִिͰΞϓσ͢Δͱݴͬͯͨʣ w
TypeORM ʹൺͯରԠ͢Δσʔλϕʔε͕ߜΒΕͯΔ ͷɺܽͰ͋Δ͕རͰ͋Γͦ͏
vs TypeORM (2/2) w Photon JS ORM Lift JS Migration
͕ಠཱͯ͠ ಈ͘ͱ͍͏ͷNodeͬΆ͖ͯ͘ʢΈͷ w ԿΑΓɺ·ͩv0.xͰ͋ΓProductionͰͷ༻ਪ͞ Ε͍ͯͳ͍ͷͰɺશମతʹࠓޙʹظͱ͍͏ײ͡ w ʢTypeScript Ͱॻ͚ΔORM͕ͦΜͳʹଟ͘ͳ͍தͰɺ બࢶ͕૿͑Δ͜ͱࣗମɺ݁ߏՁ͕͋Γͦ͏ʣ
·ͱΊ 3
·ͱΊ w όοΫΤϯυ͜ͱ͡ΊʮTypeScript + Express + Prisma Frameworkʯ͕͍͍͔͠Εͳ͍Α w ࣗͷใΛίϯςϯπʹͨ͠ΒɺແݶʹΤϯυϙΠϯ
τΛ࡞ΕΔͷͰɺʮͱݴ͑Կ࡞Ε͑͑ͶΜʯͰ ΤλΔͱ͔ͳͦ͞͏ɺΦεεϝ
ࠓհͨ͠APIͳΜͰ͕͢
୭ಘ͔͔Βͳ͍͚Ͳ
ಛʹೝՄػߏͱ͔ ੵΜͰͳ͍ΜͰ
୭Ͱୟ͚·͢
ͱ͍͏Θ͚Ͱ
Ҏ্
גࣜձࣾσΟʔɾΤψɾΤʔσβΠϯຊ෦αʔϏεσβΠϯ෦%&(( ౻ݪ৻ଠBLB1$IBO APIʹͳΖ͏ FROKAN x UIT #2 - ΕLT ότϧ
Ͱͨ͠
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠