With OkHttp we can make HTTP request then get response from server:
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
Then with Gson lib convert response to object we need.
This is from Square/OkHttp doc:
Its request/response API is designed with fluent builders and immutability. It supports both synchronous blocking calls and async calls with callbacks
I read from Stackoverflow:
Retrofit uses OkHTTP automatically if available.
So my questions are:
- What, exactly, is Retrofit for?
- What Retrofit can do that OkHttp cannot?
I think OkHttp and Gson solve the request API problem, but what problem does retrofit solve for us?