Network ํต์ ์ ํ ๋ ์ฃผ๋ก ์ฌ์ฉ๋๋ Library์ธ Retrofit๊ณผ Room์ RxJava์ ํจ๊ป ์ฌ์ฉํ์ฌ ํ์ฉ ํด ๋ด ๋๋ค.
์ด๋ฒ ํฌ์คํ ์์๋ Retrofit / Room library์ ๊ธฐ์ด์ ์ด์ ์ ๋์ด ์ค๋ช ํ๊ธฐ ๋ณด๋ค, RxJava์ Retrofit / Room์ ํจ๊ป ์ฌ์ฉํ๋ ํํ๋ฅผ ์ฃผ๋ก ๋ค๋ฃน๋๋ค.
Retrofit์ ๋ํ ์์ธ ๋ด์ฉ์ Docs๋ฅผ, Room์ ๋ํ ์์ธ ๋ด์ฉ์ Docs๋ฅผ ์ฐธ์กฐ ํด ์ฃผ์ธ์.
Retrofit์ ์ค์นํ๊ณ ์ ํ๋ ๋ชจ๋์ gradle ํ์ผ์ Retrofit Dependency๋ฅผ ์ถ๊ฐ ํด ์ค๋๋ค.
// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
Retrofit์ ํ์ฉํ ๋คํธ์ํฌ ํต์ ๊ฒฐ๊ณผ ํํ๋ฅผ RxJava2์ Stream ํํ๋ก ๋ณํํด์ฃผ๋ adapter dependency๋ฅผ ์ถ๊ฐ ํด ์ค๋๋ค.
// retrofit-rxJava
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.2'
ํ์ํ๋ค๋ฉด Retrofit ํต์ ์ ์ฌ์ฉ๋๋ ์ ํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ dependency๋ค๋ ์ค์น ํด ์ค๋๋ค.
// gson converter
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
// OkHttp
implementation 'com.squareup.okhttp3:okhttp:3.14.7'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.2'
์์์ ์ถ๊ฐํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ฒ์ ์ ํ์์ ๋ฐ๋ผ ๋ณ๊ฒฝํ์๋ฉด ๋ฉ๋๋ค.
๊ธฐ๋ณธ์ ์ธ ์ฌ์ฉ ๋ฐฉ๋ฒ์ Retrofit๊ณผ ๋์ผํ๋, ๊ธฐ์กด์๋ API interface๋ฅผ ๋ง๋ค ๋ Call<T>๊ฐ์ฒด๋ฅผ ๊ฒฐ๊ณผ ๊ฐ์ผ๋ก ๋ฆฌํด ํด ์ฃผ์ง๋ง, RxStream, ์ฆ Observable / Single / Completable ๋ฑ์ ํํ๋ก ๊ฒฐ๊ณผ ํํ๋ฅผ ์ ํด ์ค ์ ์์ต๋๋ค.