Understand How does Retrofit work
To be a good developer know what is going on under the hood
Networking is one of the most important parts of Android applications. At the early stage, we wrote our own HTTP classes to handle networking. As time passed development got easier making us dependent on libraries. We use many libraries to get the work done faster but most of us do not analyze its limitations and drawbacks. Before using any library we need to analyze three things What, Why and How. One popular library which we use for Networking is Retrofit. In this post, let's analyze these things and understand how the request gets processed inside Retrofit.
What
Retrofit is a type-safe HTTP client for Android and Java.
Why
Using Retrofit made networking easier in Android apps. As it has many features like easy to add custom headers and request types, file uploads, mocking responses, etc through which we can reduce boilerplate code in our apps and consume the web service easily.
How
To work with Retrofit we basically need the following three classes:
- A model class which is used as a JSON model
- An interface that defines the HTTP operations needs to be performed