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
410
Compose駆動開発のためのマルチモジュール化
kobaken0029
0
170
DataStoreを導入してみた
kobaken0029
1
270
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
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
760
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
190
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
フルカイテン株式会社 採用資料
fullkaiten
0
40k
SSMRunbook作成の勘所_20241120
koichiotomo
2
130
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.3k
Done Done
chrislema
181
16k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
BBQ
matthewcrist
85
9.3k
Typedesign – Prime Four
hannesfritz
40
2.4k
It's Worth the Effort
3n
183
27k
Embracing the Ebb and Flow
colly
84
4.5k
We Have a Design System, Now What?
morganepeng
50
7.2k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Navigating Team Friction
lara
183
14k
Music & Morning Musume
bryan
46
6.2k
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