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
[RailsConf 2023] Rails as a piece of cake
palkan
51
4.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
A designer walks into a library…
pauljervisheath
202
24k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Visualization
eitanlees
144
15k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Designing for Performance
lara
604
68k
Become a Pro
speakerdeck
PRO
24
5k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
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ͱ͔͋ΔͷͰ ΈΜͳΖ͏ ͓ΘΓ