OkHttp vs Retrofit: What are the differences?
OkHttp: An open source HTTP client. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth; Retrofit: A type-safe HTTP client for Android and Java. Retrofit turns your HTTP API into a Java interface.
OkHttp and Retrofit can be primarily classified as "API" tools.
Some of the features offered by OkHttp are:
- 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.
On the other hand, Retrofit provides the following key features:
- URL parameter replacement and query parameter support
- Object conversion to request body (e.g., JSON, protocol buffers)
- Multipart request body and file upload
Retrofit is an open source tool with 33.3K GitHub stars and 6.17K GitHub forks. Here's a link to Retrofit's open source repository on GitHub.
Square, Write.as, and Robinhood are some of the popular companies that use Retrofit, whereas OkHttp is used by FarmLogs, Gridle, and Tokopedia. Retrofit has a broader approval, being mentioned in 33 company stacks & 19 developers stacks; compared to OkHttp, which is listed in 9 company stacks and 7 developer stacks.