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
480
Compose駆動開発のためのマルチモジュール化
kobaken0029
0
180
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
ハイテク休憩
sat
PRO
2
150
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
560
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
290
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
320
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
380
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
160
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
220
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
120
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
360
podman_update_2024-12
orimanabu
1
270
Featured
See All Featured
Designing for humans not robots
tammielis
250
25k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Mobile First: as difficult as doing things right
swwweet
222
9k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
GitHub's CSS Performance
jonrohan
1030
460k
Bash Introduction
62gerente
608
210k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
How STYLIGHT went responsive
nonsquared
95
5.2k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Writing Fast Ruby
sferik
628
61k
Faster Mobile Websites
deanohume
305
30k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
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