skip to content

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 pageshow

explore

questions

page 2 of 2

A 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?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Retrofit.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.

open as a page

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?

level: principalimportance: should knowfreq 28%

basics

~10 s

Standardise 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.

open as a page

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?

level: principalimportance: should knowfreq 45%

basics

~20 s

Keep 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.

open as a page

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?

level: middleimportance: nice to knowfreq 24%

basics

~20 s

Retrofit 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.

open as a page

showing 31–34 of 34