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を生やすお話.pdf
Search
yagi2
August 03, 2018
0
440
おうちにAPIを生やすお話.pdf
Kyoto.LT 第21回
https://kyotolt.connpass.com/event/93043/
yagi2
August 03, 2018
Tweet
Share
More Decks by yagi2
See All by yagi2
Kotlin DSLを理解してみる / Understanding Kotlin DSL
yagi2
4
2.3k
略解 The Navigation Architecture Component
yagi2
1
200
10分で完全に(雰囲気を)理解するマテリアルデザイン
yagi2
1
400
KtorでおうちAPIをリプレースした話
yagi2
1
990
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
Navigating Team Friction
lara
183
14k
A Tale of Four Properties
chriscoyier
156
23k
How to Ace a Technical Interview
jacobian
275
23k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Scaling GitHub
holman
458
140k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
The Pragmatic Product Professional
lauravandoore
31
6.3k
The Invisible Side of Design
smashingmag
297
50k
Transcript
͓͏ͪʹAPIΛੜ͓͢ 2018/08/03 Kyoto.LT #21 γʔαʔגࣜձࣾ Itsuki AOYAGI (@yagi2)
ࣗݾհ • ੨༄ थʢItsuki AOYAGI) • ͗ʹ͍ʢ@yagi2, @yaginierʣ • γʔαʔגࣜձࣾ
• AndroidΞϓϦΤϯδχΞ • ͓͏͕ͪେ͖
ࣗݾհ • ੨༄ थʢItsuki AOYAGI) • ͗ʹ͍ʢ@yagi2, @yaginierʣ • γʔαʔגࣜձࣾ
• AndroidΞϓϦΤϯδχΞ • ͓͏͕ͪେ͖
࠷ۙ؆୯ʹ͓͏ͪͱITΛܨ͛ΒΕΔ ɾGoogle Home ɾAmazon Alexa ɾHomePod ……
࠷ۙ؆୯ʹ͓͏ͪͱITΛܨ͛ΒΕΔ ɾGoogle Home ɾAmazon Alexa ɾHomePod …… ͕ɺҙ֎ͱͰ͖Δ͜ͱݶΒΕ͍ͯΔ……
σϑΥϧτͰແ͍ػೳΛΔʹ • ࣗͰΞΫγϣϯεΩϧΛ͏ • ൺֱత؆୯ʹՃͰ͖Δ͕ॊೈੑऑ͍ • IFTTTΛͬͯWebhook͍ͯ͠Ζ͍ΖΔ • Webhook͢ΔͷͰՄೳੑແݶେ͕ͩ༻ҙ͢Δͷଟ͍
σϑΥϧτͰແ͍ػೳΛΔʹ • ࣗͰΞΫγϣϯεΩϧΛ͏ • ൺֱత؆୯ʹՃͰ͖Δ͕ॊೈੑऑ͍ • IFTTTΛͬͯWebhook͍ͯ͠Ζ͍ΖΔ • Webhook͢ΔͷͰՄೳੑແݶେ͕ͩ༻ҙ͢Δͷଟ͍
͓͏ͪAPI
APIʢAPlication Interfaceʣ ͬͯΔਓ
APIͬͨ͜ͱ͋Δਓ
API࡞ͬͨ͜ͱ͋Δਓ
ࣗʹAPIαʔό͕͋Δਓ
͓͏ͪAPI • ࣗͷ͋Ε͜ΕΛHTTP(S)ܦ༝Ͱ͋Ε͜ΕͰ͖ ΔΑ͏ʹ͢Δͭ • ͓͏ͪͷঢ়ଶʢGETʣ • Ոిͷૢ࡞ʢPOSTʣ
ԿΛ࣮ݱ͍͔ͨ͠ • PCͷిݯΛೖΕ͍ͨʢWake on LANʣ • ΠϯλʔωοτϥδΦͷૢ࡞Λ͍ͨ͠ • ΤΞίϯͷՈిͷૢ࡞Λ͍ͨ͠ •
෦ͷԹͱ͔औΓ͍ͨ
ࠓճेീ൪ͷKotlinͰAPIΛ࡞Δ
KotlinͰͷAPI • બࢶ͍Ζ͍Ζ͋ΔʢͳʹͤJavaͷࢿ࢈͕͑ΔͷͰʣ • SpringBootવΓ…… • KotlinͱSpring BootΛͬͯαΫοͱୟ͚ΔAPIΛ࡞Δ • ͔͠͠KotlinͰΓ͍ͨ
• ͷͰKtorͱ͍͏ϑϨʔϜϫʔΫΛ͏
Ktor • ΊͬͪΌബ͍WebΞϓϦͷϑϨʔϜϫʔΫ ( https://github.com/ktorio/ktor ) • ඇಉظॲཧ͍͍ײ͡ʹͳ͍ͬͯΔ • KotlinͷCoroutinesͱ͍͏ػೳ
fun main(args: Array<String>) { embeddedServer(Netty, 8080) { routing { get("/") { call.respondText("Hello, world!", ContentType.Text.Html) } } }.start(wait = true) }
KtorͰͷAPI • https://github.com/yagi2/Kaya • Private Repository • ͱ͍࣮͑ࠓճͷຊ࣭తͳ෦Ͱͳ͍ͷͰলུ • KtorͰ͓͏ͪAPIΛϦϓϨʔεͨ͠
- Speaker Deck
ͯ͞APIͨ͠
ͳͥAPIΛ࡞ͬͨͷ͔ • Application Interface • ͭ·ΓAPIΛ༻ҙ͢Ε͍ΖΜͳͱ͜Ζ͔Β͑Δ • Web,εϚϗ,HomeܥσόΠε
ࠓճͷߏ • API • Kotlin+KtorΛRaspberryPi্Ͱಈ͔͢ʢࣗʣ • ΫϥΠΞϯτ • WebϒϥβʢૉHTMLʣ •
AndroidΞϓϦʢेീ൪ʣ • Google Home miniʢࣗʣ ※DDNSΛͬͯࣗ֎͔ΒAPIʹΞΫηεՄೳ
ྑ͍ • ͓͏ͪͷ͋Ε͜Εʹର͢ΔೖྗͷΠϯλʔϑΣʔε͕૿͑ͨ • εϚϗࣾձͳݱʹͽͬͨΓ • ೖྗΠϯλʔϑΣʔε͕ଟ͍ʹӽͨ͜͠ͱͳ͍࠷ߴ • ͳΜͳΒcurlͰՈిૢ࡞Ͱ͖Δ •
͓͏ͪͷ͋Ε͜ΕΛҰݩཧͰ͖Δͷྑ͍ • APIΛ࡞Δೳྗؒҧ͍ͳ্͕͘Δ
ྑ͘ͳ͍ • ͳΜ͔RasPi͕ࢮΜͩΓϓϩηε͕ࢮΜͩΓ͢Δ • MackerelͰࢮ׆ࢹ͍ͯ͠Δ • ঢ়ଶΛRasPiʹͨͤ͗͢Δͱࠓਖ਼نͷϦϞίϯ͔Βૢ࡞ Λͨ͘͠ͳ͘ͳΔ • APIΛհ͞ͳ͍ͷͰঢ়ଶཧ͕໘ʹͳΔ
ࠓޙΓ͍ͨ͜ͱ • ࠓRESTfulAPIͳͷͰGraphQLʹͨ͠Γ͍ͨ͠ɻ • WebUI࡞Γ͍ͨ • Թͱ͔֎෦ͷՈిૢ࡞ɺऔಘʹ͍ΖΜͳόΠφϦ͕ґଘͯ͠ ΔͷͰDockerͱ͔ͰυΧυΧ͍ͨ͠
࣮ࡍʹى͖ͨා͍
ͦͷ̍ ͳΜ͔͍Ζ͍Ζઢͯͨ͠ΒLED͕ ম͖͖Εͨ
ిؾͷษڧΛ͔ͬ͠Γ͠·͠ΐ͏
ͦͷ̎ ͳΜ͔উखʹPC͕͍ͨΓϥδΦ ͕͍ͨΓ͢Δոحݱ
https://twitter.com/rombulow/status/990684453734203392
Կ͕ى͖ͨͷ͔ • GETͰτάϧͳϦΫΤετΛ࣮͢Δ • ςϨϏʹGET → ిݯONͳΒOFF OFFͳΒON • Chromeͷ৽نλϒ։͍ͨͱ͖ͷ࠷ۙ։͍ͨϖʔδʹAPI
͏ϖʔδ͕͋ΔͱGET͕ϦΫΤετ͞ΕΔ
HTTPΛཧղͤΑ HTTPͷGETႈʹ͢Δ͖Ͱ ͋ͬͯɺ෭࡞༻ΛͨͤΔͱ Googleͱ͔ͷBOTͱ͔ͷΫϩʔϥ ͕͓Ոʹ৵ೖͯ͘͠Δ
ͱ͍͑ΊͪΌΜ͜ศརͩ͠ ݱGoogle Homeͱ͔͋ΔͷͰ ΈΜͳΖ͏ ͓ΘΓ