

Although sometimes it might be sufficient, in most cases we would like to make use of some serialization library when dealing with payloads. Serialization & Deserializationīy default, Retrofit allows us to work only with OkHttp’s RequestBody and ResponseBody objects. If you are working with Maven, then you can add it to your project with the following lines: Īlternatively, we can use Gradle to fetch the library: // adle In my examples, I will be using version: 2.9.0. Moreover, depending on when you are reading this article, the latest stable version can be different and I recommend using the latest one. It’s worth mentioning, that Retrofit requires at minimum Java 8+ or Android API 21+, so it won’t be compatible with the legacy codebase. If you are looking for a library, which will help you to integrate external API in your mobile application, or a back-end service written in Java or Kotlin, then Retrofit is definitely worth a try. Let’s start by answering the question: what exactly the Retrofit is? It is a type-safe HTTP client for Android and Java. I will walk you step by step through its features, capabilities and a few obstacles you may encounter when using it. Make sure to require Internet permissions in your AndroidManifest.xml file: Īdd the following to your app/build.This time, I would like to show you how to use Retrofit 2 with Kotlin. Once the data is downloaded then it is parsed into a Plain Old Java Object (POJO) which must be defined for each "resource" in the response. This library makes downloading JSON or XML data from a web API fairly straightforward. See this guide to understand how OkHttp works.

The library provides a powerful framework for authenticating and interacting with APIs and sending network requests with OkHttp. Retrofit is a type-safe REST client for Android, Java and Kotlin developed by Square.
