Learning Android Development

OkHttp or Retrofit for Android?

Deciding which to pick when doing a project

If you work on networking in Android, you probably heard of OkHttp and Retrofit. They are not really totally different. In fact, Retrofit is just a higher-level API wrapped around OkHttp. So the questions are

  • What does Retrofit really provide on top of OkHttp?
  • Should we consider using OkHttp directly?

There are several StackOverflow like this and this talks about them as well. Let me give you more detailed descriptions below.

What Retrofit provides on top of OkHttp

Structured URL and Parameter construction

In Retrofit, you construct your retrofit object by providing the BASE_URL.

Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build()

Then in your service interface API, you have all the query parameter defined properly

@GET(BASE_PATH)
fun hitCountCheckCall(@Query(PARAM_ACTION) action: String,
@Query(PARAM_FORMAT) format: String,
@Query(PARAM_LIST) list: String…

--

--