Consume an API, Web Service with Retrofit on Android

Tutorial to create a Pokédex app from scratch. The app uses Retrofit library to consume an API on Android. In addition to using Glide to download images.

What you'll learn

  • Consume an API or Web Service with Retrofit
  • Use a RecyclerView component in grid mode
  • Handle RecyclerView events

What you'll need

Introduction

API (0:22)

Google Chrome Extension (1:10)

Images (1:47)

URL to obtain the images of the pokemon by their number.

̶h̶t̶t̶p̶s̶:̶/̶/̶p̶o̶k̶e̶a̶p̶i̶.̶c̶o̶/̶m̶e̶d̶i̶a̶/̶s̶p̶r̶i̶t̶e̶s̶/̶p̶o̶k̶e̶m̶o̶n̶/̶2̶5̶.̶p̶n̶g̶

Update: The previous URL stopped working but you can get the image directly from the repository like this:

https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/25.png

Pikachu is the pokemon number 25.

Pikachu

Retrofit

2:02: Dependency to use Retrofit in the module build.gradle

c̶o̶m̶p̶i̶l̶e̶ ̶'̶c̶o̶m̶.̶s̶q̶u̶a̶r̶e̶u̶p̶.̶r̶e̶t̶r̶o̶f̶i̶t̶2̶:̶r̶e̶t̶r̶o̶f̶i̶t̶:̶2̶.̶1̶.̶0̶'̶

Update: compile is deprecated and there are new versions.

implementation 'com.squareup.retrofit2:retrofit:2.7.1'

Release numbers, more information and Retrofit documentation:

The Code

The complete code:

The master branch was updated with the migration of AndroidX and the update of gradle tools. If you want to see exactly the same version of the video, it is in the video branch.

PublishedMar 29, 2020
Last updateMar 29, 2020