OkHttp is an HTTP client library tuned for efficient networking on Android, Java, and GraalVM native images. It offers synchronous and asynchronous call APIs with a fluent request builder.
Overview
OkHttp is an HTTP client for JVM applications, Android apps, and GraalVM native builds. It targets everyday application networking with defaults aimed at speed and resilience: HTTP/2 sharing on one host, connection pooling, transparent GZIP, and response caching for repeat requests.
When connections fail, it can retry against alternate IP addresses, which helps IPv4 and IPv6 deployments and redundant endpoints. TLS support includes modern options such as TLS 1.3, ALPN, and certificate pinning, with configurable fallback for broader connectivity. The public API uses immutable request and response objects with builder-style construction and supports both blocking calls and callback-based async execution.
The client follows contemporary HTTP specifications and deliberately limits exotic configuration, such as rejecting GET requests with bodies. Optional companion artifacts cover logging, Server-Sent Events, DNS over HTTPS, Brotli, coroutines, and TLS helpers. MockWebServer provides an in-project HTTP test double for basic client testing, though the project notes that heavy testing needs may outgrow it.
Android support starts at API level 21 and integrates with AndroidX Startup unless the app initializes OkHttp manually. Java 8+ and GraalVM native image builds are supported, with published JVM and Android Maven artifacts and Java 9 module boundaries on recent releases.
Key features
- HTTP/2 and connection pooling
- Response caching and GZIP
- TLS 1.3, ALPN, and pinning
- Sync and async request APIs
- Alternate address connection retry
- Kotlin Multiplatform publishing
- MockWebServer test helper
- GraalVM native image support
Use cases
- Android app HTTP traffic
- JVM backend HTTP calls
- REST and JSON API clients
- HTTP client integration tests
- Native image CLI tools