Retrofit 2.X - Response vs Call - What is the recommended to use?

Viewed 935

Please can you explain to me the difference of "Call" and "Response" in retrofit 2.X, What is the recommended way to use? and the difference of each. For instance I want to consume a 4 API calls with coroutines at the same time some might wait for response of other API and some will not. Thank you.

1 Answers

They are types for different purposes, but they come hand in hand.

Call<T> is a container that "sends a request to a webserver and returns a response".

Response is a container that delivers a result back to you, either from calling enqueue(Callback<T> callback) (asynchronously) and implementing Callback<T> or by calling execute() (synchronously). A Response can be either successful or a failure.

In other words, first you do a Call and then you get back a Response.

Documentation

Related