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
Modern REST Communicate for Android
Search
kobayashi_kento
May 23, 2016
Technology
0
1.5k
Modern REST Communicate for Android
社内発表用スライド
kobayashi_kento
May 23, 2016
Tweet
Share
More Decks by kobayashi_kento
See All by kobayashi_kento
Kotlinの好きなところ
kobaken0029
0
540
Compose駆動開発のためのマルチモジュール化
kobaken0029
0
190
DataStoreを導入してみた
kobaken0029
1
280
Epoxyを用いたレイアウト構築術
kobaken0029
1
210
Androidエンジニアが1週間でiOSアプリ開発を学び、1ヶ月で大規模アプリ開発にJOINした話
kobaken0029
0
3k
AndroidでモダンREST通信してみたった
kobaken0029
0
250
Other Decks in Technology
See All in Technology
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
6
54k
FODにおけるホーム画面編成のレコメンド
watarukudo
PRO
2
270
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
3
440
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
850
[IBM TechXchange Dojo]Watson Discoveryとwatsonx.aiでRAGを実現!座学①
siyuanzh09
0
110
2024AWSで個人的にアツかったアップデート
nagisa53
1
110
ドメイン駆動設計の実践により事業の成長スピードと保守性を両立するショッピングクーポン
lycorptech_jp
PRO
12
1.7k
三菱電機で社内コミュニティを立ち上げた話
kurebayashi
1
350
JuliaTokaiとJuliaLangJaの紹介 for NGK2025S
antimon2
1
110
Amazon Q Developerで.NET Frameworkプロジェクトをモダナイズしてみた
kenichirokimura
1
200
生成AI × 旅行 LLMを活用した旅行プラン生成・チャットボット
kominet_ava
0
150
KMP with Crashlytics
sansantech
PRO
0
240
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Unsuck your backbone
ammeep
669
57k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Embracing the Ebb and Flow
colly
84
4.5k
Code Reviewing Like a Champion
maltzj
521
39k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Become a Pro
speakerdeck
PRO
26
5.1k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Transcript
Modern REST Communicate for Android 2016.5.20 @kobaken42
Agenda • Keyword • Βͳ͍͜ͱ • RESTʹ͍ͭͯ • ༻ϥΠϒϥϦհ •
αϯϓϧΞϓϦͷ࣮(ϨϏϡϫʔ͋Γ) • Keyword(͓͞Β͍)
Keyword • REST(RESTful) • (ؔܕ)ϦΞΫςΟϒϓϩάϥϛϯά(FRP) • ReactiveX(ϦΞΫςΟϒΤΫεςϯγϣϯ) • Parse(ύʔε)
Βͳ͍͜ͱ • Androidʹؔ͢Δઆ໌(Activity, Fragment, Lifecycle etc…) • RESTɺFRPʹؔ͢Δৄࡉͳઆ໌ • ϨΨγʔͳ࣮ͱͷൺֱ
ʊਓਓਓਓʊ ʼ REST ʻ ʉY^Y^Y^Yʉ
Webͷ ΞʔΩςΫνϟελΠϧͷҰͭ
ύϥϝʔλΛࢦఆͯ͠ ಛఆURLʹHTTP(s)ͰΞΫηε XML or jsonͰ݁Ռ͕ฦ٫͞ΕΔ
ύϥϝʔλ(Input)͕ಉҰͳΒ ৗʹಉ݁͡Ռ(Output)͕ظͰ͖Δ (γεςϜͷঢ়ଶηογϣϯʹґଘ͠ͳ͍)
(ͪΐͬͱཚ͚ͩͲ) ҰߦͰݴ͏ͱ
Ϧιʔεॏࢹઃܭ
RESTful item_url -> items/:id new_item_url -> items/new edit_item_url -> items/:id/edit
items_url -> items
Not RESTful
ίϨͰΘ͔Βͳ͍ਓ ϫγϫγMAXͰʙʂʂ ͦΜͳͷ͋Μ·Γʹ͜ʙʂʂ
ຊ
ϦΞΫςΟϒͳ REST௨৴Λ࣮ݱͨ͠ αϯϓϧΞϓϦΛ࡞͍͖ͯ͠·͢
༏लͳϨϏϡϫʔͷྗΛ आΓͳ͕Β࣮͍͖ͯ͠·͢Αʂ
༻ϥΠϒϥϦͷհ
༻ϥΠϒϥϦ(Plugin) • Retrofit • RxAndroid • Retrolambda • Lombok •
butterknife(DataBindingʹஔ͖͑·ͨ͠)
Retrofit v2.0.2 • AndroidͱJavaͷͨΊͷܕ҆શͳ HTTPΫϥΠΞϯτ • ෦ͰOkhttpΛ༻ • AsyncLoaderͱ͏͓͞Β •
jsonύʔεͱ͔ॾʑͬͯ͘ΕΔ • Apache HTTP ClientʁūŬťƀŘŶƂŜƃūŘ!!
RxAndroid v1.2.0 • RxJavaΛแ͍ͯ͠ΔAndroid͚ ReactiveX • ϦΞΫςΟϒϓϩάϥϛϯάग़དྷΔ • ඇಉظॲཧ͕؆୯ʹॻ͚Δ (AsyncTaskͳΜͯͳ͔ͬͨ)
• ڞ௨ͷΠϯλʔϑΣʔεͱͯ͠׆༻ • View͔ΒͷΠϕϯτΛड͚औΔ • ίʔϧόοΫͷҰݩཧ etc…
Retrolambda • AndroidͰϥϜμ͕ࣜॻ͚ΔΑ͏ʹ ͳΔPlugin • Method ReferenceʹରԠ • RxAndroid, Stream
APIͱͷซ༻ར ༻Ͱ΄΅Java8ڥʹʂ
Lombok v1.16.8 • JavaͰΑ͋͘ΔϘΠϥʔϓϨʔτ ίʔυΛγϯϓϧʹͯ͘͠ΕΔ • getter, setterͷهड़ෆཁʹ • nullνΣοΫΛࣗಈͰͬͯ͘ΕΔ
• MITϥΠηϯε
ϥΠϒϥϦհ͜͜·Ͱ
Δ͜ͱ
Δ͜ͱ • ༻ϥΠϒϥϦΛGradleͰએݴ • REST௨৴ͷͨΊͷAPIΠϯλʔϑΣʔε࡞ • Ϩεϙϯε༻ͷΦϒδΣΫτΛ࡞ • ϦΞΫςΟϒϓϩάϥϛϯάͰREST௨৴ʂ
Ͱૣ
gradleʹهड़ͯ͘͠Ͱ
build.gradle(appԼ)
None
None
࣍
WebAPIͷInterface ࡞ΔͰ
ࠓճొෆཁͳ͓खܰAPIΛ ར༻͍ͨ͠Μʂ
༻API • WeatherHacks
WeatherHacksApi.java
None
None
ResponseObject(Entity) ࡞ΔͰ
ResponseObject.java
None
None
Լ४උऴΘΓ
ͦΕ͡Όɺຊ൪ߦ͘Ͱ
͜Ε͔ΒΔ͜ͱ
ࡾߦͰ
Activity(Fragment)ʹ RetrofitΦϒδΣΫτΛੜͯ͠ subscribeʂ
MainActivity.java
MainActivity.java
MainActivity.java
͜Ε͚ͩʂ
ͱ
ࢥΘͤͯ
AndroidManifest.xmlʹ Internet௨৴ͷͨΊͷ Permissionهड़͕ඞཁͦ͏ɾɾɾ
None
AndroidManifest.xml
AndroidManifest.xml
None
Keyword(͓͞Β͍) • REST(RESTful) • (ؔܕ)ϦΞΫςΟϒϓϩάϥϛϯά(FRP) • ReactiveX(ϦΞΫςΟϒΤΫεςϯγϣϯ) • Parse(ύʔε) •
ঁਆͷΜͨΜ
ΈΜͳϦΞΫςΟϒʹ REST௨৴͠Αͬˑ
None
https://github.com/kobaken0029/RestSample