Retrofit
Retrofit turns an annotated Kotlin interface into HTTP calls, with converters for bodies and call adapters for return types. Interviewers probe the layers beneath the annotations.
on this pageshowhide
explore
- Service Interfaces & Annotations6 questions
- Converters6 questions
- Call Adapters & Coroutines6 questions
- OkHttp & Interceptors6 questions
- HTTP Errors & Failures5 questions
- Multipart & File Uploads5 questions
questions
page 2 of 2A Retrofit service compiles, yet one endpoint throws IllegalArgumentException on its first call; how does create() turn the interface into requests, and how do you catch such declaration errors earlier?
basics
~20 sRetrofit.create() returns a java.lang.reflect.Proxy that parses each method's annotations on its first call and caches the result, so a bad declaration fails only when that method runs. validateEagerly(true) parses every method inside create(), which a unit test can exercise.
As Android lead, which JSON converter should a Retrofit codebase standardise on, and how do you move 60 Gson endpoints without a big-bang switch?
basics
~10 sStandardise on one JSON converter that respects Kotlin nullability, usually kotlinx.serialization, and migrate endpoint by endpoint: a routing factory sends opted-in methods to the new converter, and Gson stays last as the default.
As Android lead, should your Retrofit data layer report outcomes as a thrown HttpException, Response<T> or a sealed result, and where should that mapping live?
basics
~20 sKeep Retrofit's exceptions inside the data layer: map every call once into a sealed result with success, HTTP error with a parsed body, network failure and unexpected cases. Callers then handle failures exhaustively instead of remembering which exceptions to catch.
In a Retrofit app, how can one OkHttp interceptor apply per-endpoint behaviour, such as skipping the auth header, by reading Retrofit's Invocation tag?
basics
~20 sRetrofit attaches an Invocation to every OkHttp request as a tag; an interceptor reads request.tag(Invocation::class.java), takes its method(), and checks a custom annotation on that service method to skip auth, change a timeout or opt into retries.
showing 31–34 of 34