Announcing OkHttp

Square’s new HTTP client for Android and Java.

Square Engineering
May 6, 2013 · 2 min read

Written by Jesse Wilson.

Heads up, we’ve moved! If you’d like to continue keeping up with the latest technical content from Square please visit us at our new home https://developer.squareup.com/blog

Android has two HTTP clients built-in:

  • Apache HTTP Client is stable yet basic.
  • HttpURLConnection supports advanced features, but suffers a few annoying bugs on older devices.

At Square, we want it all: advanced features that work right on every device. We also want to ship new tech without waiting for new Android releases.

OkHttp is our new open source HTTP client for Android and Java. Our goal is to build the most robust, most efficient HTTP client.

Robust

For example, if your web service is hosted in multiple data centers for redundancy, OkHttp will attempt each IP address until it finds one that works. It also recovers from failed TLS handshakes and troublesome proxy servers.

The code is based on the latest version of Android’s HttpURLConnection, which has been battle-tested against real-world web servers.

Efficient

When OkHttp does hit the network, it uses transparent response compression and a sophisticated connection pool. These on-by-default optimizations save bandwidth and reduce latency.

My favorite feature is the SPDY backend. This is Google’s efficient new wire transport layer that is the starting point for the new HTTP 2.0 draft. SPDY enables multiple concurrent requests to share a single socket. This lowers the cost of HTTPS so you no longer have to choose between security and performance.

Give it a try!

If you’re writing a new app, the project website has code examples to get you started.

Get OkHttp from Maven or download it from the project website.

This post is part of Square’s “Seven Days of Open Source” series.


Square Corner Blog

Buying and selling sound like simple things - and they…

Square Engineering

Written by

The official account for @Square Engineering.

Square Corner Blog

Buying and selling sound like simple things - and they should be. Somewhere along the way, they got complicated. At Square, we're working hard to make commerce easy for everyone.

Square Engineering

Written by

The official account for @Square Engineering.

Square Corner Blog

Buying and selling sound like simple things - and they should be. Somewhere along the way, they got complicated. At Square, we're working hard to make commerce easy for everyone.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store