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
870
この先生きのこるためのPostCSS実践入門
p1ch_jp
1
1.5k
エンジニアのためのデザインの話
p1ch_jp
0
910
Other Decks in Programming
See All in Programming
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
120
return文におけるstd::moveについて
onihusube
1
860
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
2
770
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
920
Jakarta EE meets AI
ivargrimstad
0
230
Full stack testing :: basic to basic
up1
1
930
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
103 Early Hints
sugi_0000
1
220
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Bash Introduction
62gerente
608
210k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Invisible Side of Design
smashingmag
298
50k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
A better future with KSS
kneath
238
17k
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 ότϧ
Ͱͨ͠
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠