👏👏 Retrofit review 👏👏

This is a spin-off of the “Android RxJava in 5 minutes” article I wrote a while back and has stuff that you might find useful for this one.

You can find it here:

What is an API anyway?

It seems like everyone and their mother is running an API on the internets. If you are not too sure what an API is, or how to consume (????) it no less, fear not. This tutorial will teach you how you too can copy-paste your way to a lead dev position in Silicon Valley.

Cats are important

Doing something of value is paramount to finding happiness aside from browsing stale memes on r/programmerhumor.

So, of course, we will concentrate on the most important aspect of all, cats (or dogs if you are into that sort of thing).

Retrofit might as well be a synonym for boring and the tutorials out there are really trying hard to be the solution to chronic insomnia so let’s just write something man.

Source code can be found here:

What you will need

Just click File -> New project in Android Studio 3 and include Kotlin support, AndroidX artifacts and an empty activity pre-made. Press next on everything. Jetbrains really understands its market (monkeys banging the keyboard like me) and basically writes everything for you these days.

Let the thing finish building.


Go to the build.gradle (Module: app) file in the dependencies block. It should have these lines in it at least:

The cat whisperer

There’s loads of public APIs out there to test out.

We gonna go for this one here I found randomly browsing:

Request an API key and have a look at the docs. Or you can just follow along after you get your key.

Setting things up like you know what you are doing

Get yourself a generic repository class like this one below.

Reading the docs and going here https://api.thecatapi.com/v1/images/search we get some JSON back.

Put that in the http://www.jsonschema2pojo.org/.


Source Type : JSON

Annotation style : Gson

Hit preview and you will see an Example class created. This will give you some guidance on the data class you will need so you can convert the response from the server to something of meaning to you.

Here it is anyway:

Need a file to put the GET request in too.

And the final piece of the puzzle tying these together.

I lied.

Retro cat

Get your MainActivity and set up a button so you can test this request yourself.

Since RxJava is being used you gotta be lifecycle aware, hence the compositeDisposableOnPause variable. For more info check the Android RxJava in 5 minuteslinked at the top.

The activity:

Someone might say that all this is really verbose and long-winded.

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Plus, this is a 5 minute tutorial, what did you expect?

Wew lad

Before you run this make sure to replace the apiKey variable with your own, personal, key.

Give it a run and tap the button. There should be a toast popping up telling you what happened (good or bad). The Logcat will have more information too!

For now, it’s a bunch of links, which don’t seem all that great. Using Glide or Picasso will take care of that problem.

Follow on to the next part where we try to introduce the ViewModel and take the logic out of the MainActivity and into the ViewModel.


Smash like and subscribe guys new videos every Wednesday




Android dude @JustEatUK

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium


Android Layout :ViewGroups and Views

Arc8 pre-season update!

Solution for “AndroidStudio: Entrypoint file not found at main.dart”

Perfectus: Dark Theme

Create gradient on button in Flutter

Building a TodoList in Flutter

No more LiveData in Your Repository: There are better options.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Costa Fotiadis

Costa Fotiadis

Android dude @JustEatUK

More from Medium

FeignClients With KotlinCoroutines

Kickstarting Ads Kit by integrating Interstitial Ads in Application (Kotlin)

Set up an Android CI using GitHub Actions

Tabbed SlidingPaneLayout (Primary/Detail) using the Navigation Component Library ➡️🗔✨