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
450
おうちに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.4k
略解 The Navigation Architecture Component
yagi2
1
200
10分で完全に(雰囲気を)理解するマテリアルデザイン
yagi2
1
400
KtorでおうちAPIをリプレースした話
yagi2
1
1k
Featured
See All Featured
Building Your Own Lightsaber
phodgson
103
6.1k
A better future with KSS
kneath
238
17k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Typedesign – Prime Four
hannesfritz
40
2.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Automating Front-end Workflow
addyosmani
1366
200k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
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ͱ͔͋ΔͷͰ ΈΜͳΖ͏ ͓ΘΓ