Making Retrofit Work For You by Jake Wharton
Why Stack Overflow recommends it
Stack Overflow users link it when answering Retrofit questions about OkHttp configuration, unwrapping envelope responses with custom converter factories, and reusing Retrofit setup code.
Recommended by 3 people across 3 different months, 2017 to 2019.
What it is
A conference talk by Jake Wharton, a Retrofit and OkHttp maintainer, on configuring Retrofit 2 for Android and Java HTTP clients. It covers endpoint declarations on interfaces, custom serialization such as converter factories, and execution mechanisms including sync, async and error handling.
What people said
Recommends peitek · 2017-01 · Stack Overflow · on “Remove unwanted string from retrofit response”
You might be able to implement a converter, which acts before the GsonConverter. It strips away that secure part at the beginning and end and then delegates the valid JSON rest to the actual Gson converter. Jake Wharton outlined a similar approach in his talk: [this video]
Recommends azizbekian · 2017-08 · Stack Overflow · on “Why developers set OkHttp to Retrofit if Retrofit already uses OkHttp internally”
You should explicitly provide an OkHttp instance to Retrofit , otherwise Retrofit would implicitly perform .client(new OkHttpClient()) , thus you'd not get a lot of smart things , e.g. disk caching, connection pooling. See how Jake Wharton clarifies the case in "Making Retrofit Work For You" talk [this video] . Edit Above mentioned case makes sense if you have multiple retrofit instances.
Recommends Raghunandan · 2018-01 · Stack Overflow · on “How can i reuse Retrofit code in Android”
also i would suggest you to go through this video [this video] You need not have retrofit and retrofitScr. For more info watch the video
Cites David Medenjak · 2017-08 · Stack Overflow · on “Retrofit2: How to properly check the validity of response.body()?”
Is that the intended behavior? If you check the JavaDoc of Response<T> you can read @Nullable public T body() The deserialized response body of a successful response. Javadoc: Response [LINK] As it suggests, body() won't be null if the response was successful. To check for success you have isSuccessful() which Returns true if code() is in the range [200..300). So the @Nullable is a valid choice, since the response can be null in any non-success case, e.g. no network, an invalid request, or some other error. The hint in your IDE is a lint warning that checks your source code for possible sources of common errors or bugs. This is why body() might be null and why lint reports this as a warning
Cites azizbekian · 2017-10 · Stack Overflow · on “Convert retrofit callback value to return enveloped object”
Retrofit converter factories solve that issue very nicely. Jake Wharton talks about "envelope" objects in his "Making Retrofit Work For You" [this video] talk and points out how that can be solved. Having defined an envelope class - a class with some extra fields that you do not care about: public class Envelope<T> { Meta meta; List<Notification> notifications; T response; } In this POJO fields meta and List<Notification> are being returned from the backend, but in the context of android app they are not interesting to us. Assume, that the real value that you need from the response is field named response , which might be any object (because it's generic). Particularly in your example the POJO st
Cites Chris Horner · 2019-12 · Stack Overflow · on “Unwrapping enveloped responses with Retrofit, Moshi, and Kotlin”
I'm working with an API that returns responses that look like: { "irrelevantStuff": {}, "data": [] } I'd like to follow the approach demonstrated in this presentation from Jake [this video] , where he creates a Retrofit converter factory to handle and unwrap the envelope type. The only problem is that the approach shown uses Gson and Java, where as I'm trying to make use of Moshi and Kotlin. I've declared my envelope type as: data class Envelope<T>(val data: T) Any my converter factory as: object EnvelopeConverter : Converter.Factory() { override fun responseBodyConverter( type: Type, annotations: Array<Annotation>, retrofit: Retrofit ): Converter<ResponseBody, *>? { val envelopedType = Types.new