A type-safe HTTP client for Android and Java that turns annotated interface methods into network calls.
lysine-dev/okhttp
An HTTP client for the JVM, Android, and GraalVM that reuses connections, supports HTTP/2, and caches responses by default.
- Stars
- 47,090
- Forks
- 9,298
- Open issues
- 148
- Last commit
- 6 hours ago
What is it?
OkHttp is an HTTP client for Java, Kotlin, and Android applications. It is designed to be efficient by default: requests to the same host can share a socket over HTTP/2, connections are pooled when HTTP/2 is unavailable, responses are transparently gzip-decompressed, and repeat requests can be served from a response cache without touching the network.
The client also handles unreliable networks. When a service resolves to several IP addresses, OkHttp tries alternates after a failed connect. It supports TLS 1.3, ALPN, and certificate pinning, and its API uses fluent builders and immutable request and response objects. Calls can be synchronous or asynchronous with callbacks.
The project follows modern HTTP specifications (RFC 9110 through 9113, WebSocket, and server-sent events) and ships companion modules for coroutines, logging, SSE, DNS over HTTPS, and MockWebServer for testing clients. It runs on Android 5.0+ and Java 8+, and can be built as a GraalVM native image.
Key features
- 01Connection pooling and HTTP/2 multiplexing reduce latency for repeated requests to the same host.
- 02Transparent GZIP decompression and a response cache avoid redundant downloads.
- 03Falls back to alternate IP addresses when a connection attempt fails.
- 04Supports TLS 1.3, ALPN, and certificate pinning, and can use Conscrypt on Java.
- 05Provides synchronous and asynchronous call APIs built on immutable requests and responses.
- 06Includes MockWebServer for testing HTTP, HTTPS, and HTTP/2 clients.
Use cases
- Calling REST or JSON APIs from a Java, Kotlin, or Android app.
- Downloading large media or files where compression and caching save bandwidth.
- Building a native command-line HTTP tool with GraalVM.
- Writing integration tests against a mock HTTP server.
Quick start
- 1
Add the OkHttp dependency to your Gradle build
implementation("com.squareup.okhttp3:okhttp:5.5.0") - 2
Create an OkHttpClient and send a request using the Get a URL example in the README
Things to know
- Does not allow GET requests with a body.
- The response cache is not an interface with alternative implementations.
- Its Maven setup requires choosing okhttp-jvm or okhttp-android, since the okhttp artifact is empty there.
Topics
FAQ
- What is okhttp?
- An HTTP client for the JVM, Android, and GraalVM that reuses connections, supports HTTP/2, and caches responses by default. OkHttp is an HTTP client for Java, Kotlin, and Android applications. It is designed to be efficient by default: requests to the same host can share a socket over HTTP/2, connections are pooled when HTTP/2 is unavailable, responses are transparently gzip-decompressed, and repeat requests can be served from a response cache without touching the network.
- Is okhttp free to use? What license does it have?
- okhttp is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is okhttp still maintained?
- Actively maintained. The last commit to okhttp was on Oct 21, 2026.
- What can I use okhttp for?
- Calling REST or JSON APIs from a Java, Kotlin, or Android app. Downloading large media or files where compression and caching save bandwidth. Building a native command-line HTTP tool with GraalVM. Writing integration tests against a mock HTTP server.
- How do I install okhttp?
- Add the OkHttp dependency to your Gradle build: implementation("com.squareup.okhttp3:okhttp:5.5.0") Create an OkHttpClient and send a request using the Get a URL example in the README
- Where can I get okhttp?
- The source code and installation instructions are on GitHub: https://github.com/lysine-dev/okhttp
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A high-performance web server, reverse proxy, load balancer, API gateway and content cache written in C.
An interactive, TLS-capable intercepting HTTP proxy with console, command-line and web interfaces for inspecting HTTP/1, HTTP/2 and WebSocket traffic.
A CLI tool that extracts TLS/SSL certificates from servers and exports them as PEM, DER, or truststores.
A self-hosted tunnel written in Go that exposes localhost services to the internet through your own domain and server.
Java implementation of Apache Dubbo, an RPC and microservice framework for building service communication, discovery and traffic management.