Using Retrofit and Moshi
When connecting to your remote network, you can use Retrofit. Retrofit is an HTTP client that makes it easy to implement creating requests and retrieving responses from your backend server.
You can add Retrofit to your project by adding the following code to your app/build.gradle
file dependencies:
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
You can then convert the JSON response from Retrofit by using Moshi, a library for parsing JSON into Java objects. For example, you can convert the JSON string response from getting the list of movies into a ListofMovie
object for display and storage in your app.
You can add the Moshi Converter to your project by adding the following code to your app/build.gradle
file dependencies:
implementation 'com.squareup.retrofit2: converter-moshi:2.9.0'
In your Retrofit builder code, you can call addConverterFactory
and pass Moshi
ConverterFactory
:
Retrofit.Builder() ...