$ show square/retrofit
Retrofit is a mature, production-grade type-safe HTTP client library for Android and Java/Kotlin. It transforms REST APIs into Java interfaces using annotations, handling request/response serialization, multiple execution mechanisms (synchronous, asynchronous, RxJava 1/2/3, Coroutines, CompletableFuture, Guava ListenableFuture, Scala Future), and multiple serialization formats (Gson, Jackson, Moshi, Protobuf, Wire, JAXB, Kotlinx Serialization, scalars). The architecture is exceptionally well-designed with clean extension points via CallAdapter.Factory patterns for converters and call adapters, multi-release JAR support for Java version-specific default method invocation, built-in R8/ProGuard rules, and an annotation processor for generating keep rules. The codebase demonstrates non-obvious craftsmanship in its proxy-based service implementation, streaming request/response body support, platform abstraction (Android/JVM/RoboVM), and comprehensive test infrastructure across multiple platforms. Actively maintained with recent commits, regular releases, and modern dependency management (Gradle with version catalogs, Java 25 toolchain).
The LLM identified 11 files worth highlighting for reuse:
Main entry point using Builder pattern. Creates dynamic proxy implementations of service interfaces. Manages converter/call adapter factories, base URL, call factory, and callback executor. Demonstrates clean API design with fluent builder and type-safe service creation.
Abstract base for HTTP service method parsing and invocation. HttpServiceMethod implements the template method pattern for request execution, response conversion, and call adaptation. Parses annotations once at first use (or eagerly with validateEagerly), then reuses parsed metadata.
Builds OkHttp Request objects from method annotations and arguments. Handles URL resolution against base URL, path/query/header/field/part parameter encoding, request body conversion, and tag attachment. Clean separation of parsing (done once) from request creation (per call).
Core extension point for execution mechanisms. Factory pattern allows adding new return types (Observable, CompletableFuture, Flow, etc.) without modifying core. Built-in DefaultCallAdapterFactory handles Call<T>; adapters for RxJava, Coroutines, Guava, Scala live in separate modules.
Core extension point for serialization formats. Factory pattern with request/response body and string converters. Supports streaming via RequestBody/ResponseBody passthrough. Converters for Gson, Jackson, Moshi, Protobuf, Wire, JAXB, Kotlinx Serialization demonstrate the pattern's flexibility.
Platform detection and behavior abstraction (Android, JVM, RoboVM). Provides platform-specific callback executor, reflection strategy, and built-in factories. Uses multi-release JAR for Java 8/14/16 default method invocation variants in DefaultMethodSupport.
Annotation processor that generates R8/ProGuard keep rules for all generic types referenced in Retrofit service methods. Solves real-world problem where code shrinking removes types only referenced in generic positions, causing runtime failures. Handles nested generics and Kotlin suspend functions.
Mock implementation for testing without network. Uses BehaviorDelegate to forward calls to a fake implementation while simulating network behavior (latency, errors, percent failures) via NetworkBehavior. Clean separation of mock infrastructure from test logic.
Kotlin extension function with reified type parameter for type-safe service creation: retrofit.create<MyService>(). Eliminates need for .class literal and provides better type inference. Demonstrates idiomatic Kotlin API design atop Java core.
Gson converter with streaming support (withStreaming() factory). Defers serialization to HTTP execution thread via GsonStreamingRequestBody, moving CPU work off calling thread when using enqueue(). Demonstrates thoughtful threading optimization in converter implementation.
Java 14+ implementation for invoking interface default methods on dynamic proxies using MethodHandles.Lookup.unreflectSpecial. Part of multi-release JAR with Java 8 (trusted Lookup constructor) and Java 16 (InvocationHandler.invokeDefault) variants. Shows deep JVM knowledge.