Preparing to Download Bytes from a URL

Your Retrofit API interface does not support downloading an image yet. Patch that hole now. Add a new function that accepts a URL string as input and returns an executable call object (retrofit2.Call) whose result will be an okhttp3.ResponseBody.

Listing 25.5  Updating FlickrApi (api/FlickrApi.kt)

interface FlickrApi {
    fun fetchUrlBytes(@Url url: String): Call<ResponseBody>

This new API function looks a little different. It accepts a URL as input and uses that parameter value directly when determining where to download the data from. Using a parameterless @GET annotation combined with annotating the first parameter in fetchUrlBytes(…) with @Url causes Retrofit to override ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.