Fetching Data from a Network Endpoint
For the purpose of this section, we will use TheCatAPI (https://thecatapi.com/). This RESTful API offers us vast data about, well… cats.
To get started, we will create a new project. We then have to grant our app internet access permission. This is done by adding the following code to your AndroidManifest.xml
file, right before the Application
tag:
<uses-permission android:name="android.permission.INTERNET" />
Next, we need to set up our app to include Retrofit. Retrofit is a type-safe library provided by Square that is built on top of the OkHttp
HTTP client. Retrofit helps us generate Uniform Resource Locators (URLs), which are the addresses of the server endpoints we want to access. It also makes the decoding of JSON payloads easier by providing integration with several parsing libraries. Sending data to the server is also easier with Retrofit, as it helps with encoding the requests...