• HTTP/2 support allows all requests to the same host to share a socket. • Connection pooling reduces request latency (if HTTP/2 isn’t available). • Transparent GZIP shrinks download sizes. • Response caching avoids the network completely for repeat requests. • OkHttp initiates new connections with modern TLS features (SNI, ALPN), and falls back to TLS 1.0 if the handshake fails.
to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.
.addConverterFactory(GsonConverterFactory.create()) //or something else you need .client(new OkHttpClient()) //or already configured instance of the client .build();
public void onResponse(Call<List<User>> call, Response<List<User>> response) { if (response.isSuccess()) { // 2** // do what you need } else { int statusCode = response.code(); // handle an error } } @Override public void onFailure(Call<List<User>> call, Throwable error) { // handle an exception } });