talira

A meticulous HTTP client for the JVM, Android, and GraalVM

open sourceApache-2.0free

OkHttp is an HTTP client for Java, Kotlin and Android that is efficient by default: HTTP/2 lets all requests to the same host share a socket, connection pooling cuts latency when HTTP/2 isn't available, transparent GZIP shrinks downloads, and response caching skips the network for repeat requests. It recovers silently from common connection problems, tries a service's alternate IP addresses when the first fails, and supports TLS 1.3, ALPN and certificate pinning. Its request and response API uses fluent builders and immutable objects, with synchronous calls and asynchronous calls with callbacks, interceptors, WebSockets and server-sent events, and it follows the HTTP RFCs rather than being configurable for broken servers. MockWebServer, from the same project, scripts HTTP responses for tests, and Retrofit builds on OkHttp.

Problems it solves

  • an efficient HTTP client for my Android app
  • make HTTP requests from Java or Kotlin with connection pooling and HTTP/2
  • pin TLS certificates for my app's API connections
  • cache HTTP responses on Android to avoid repeat network requests
  • log or modify every HTTP request and response my app sends with interceptors
  • mock HTTP server responses in JVM unit tests
  • retry against alternate IP addresses when a server connection fails
  • WebSockets and server-sent events client for Android or the JVM

Features

  • HTTP/2 with shared sockets per host
  • connection pooling
  • transparent GZIP
  • response caching
  • recovery from common connection problems and alternate IP addresses
  • TLS 1.3, ALPN and certificate pinning
  • synchronous and asynchronous calls
  • interceptors
  • WebSockets and server-sent events
  • MockWebServer for tests
View 2 more
  • GraalVM native image support
  • Kotlin Multiplatform artifacts with a BOM

Limitations

  • Does not allow GET with a body.1
  • Cache is not an interface with alternative implementations.1
  • Works on Android 5.0+ (API level 21+) and Java 8+.1

Alternatives

The same job

These do what OkHttp does.

  1. Ktor Build asynchronous servers and clients in Kotlin
  2. Retrofit A type-safe HTTP client for Android and Java

Compare OkHttp with the top 3