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 {
    ...
    @GET
    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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.