explaingit

square/okhttp

📈 Trending46,972KotlinAudience · developerComplexity · 2/5ActiveLicenseSetup · easy

TLDR

A fast, reliable HTTP client library for Java, Kotlin, and Android apps that handles network requests with built-in caching, compression, and modern security features.

Mindmap

mindmap
  root((OkHttp))
    What it does
      Makes HTTP requests
      Caches responses
      Compresses data
    Key features
      HTTP/2 support
      Connection pooling
      TLS 1.3 security
      Certificate pinning
    How to use
      Builder pattern API
      Sync and async modes
      MockWebServer testing
    Tech stack
      Kotlin
      Java
      Android
    Use cases
      API calls
      File downloads
      Backend communication

Things people build with this

USE CASE 1

Build Android or Java apps that fetch data from REST APIs with automatic caching and compression.

USE CASE 2

Download files over HTTP with built-in retry logic that handles server failover automatically.

USE CASE 3

Write unit tests for code that makes HTTP calls using MockWebServer to simulate a real server without network access.

USE CASE 4

Implement secure API communication with modern TLS features and certificate pinning to prevent man-in-the-middle attacks.

Tech stack

KotlinJavaAndroidHTTP/2TLS 1.3

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice and license text.

In plain English

OkHttp is a library for making HTTP network requests from Java, Kotlin, and Android applications. HTTP is the protocol used to transfer data over the web, whenever your app fetches data from an API, downloads an image, or posts a form, it makes an HTTP request. The standard networking tools built into the Java and Android platforms work but have awkward APIs and lack many modern features. OkHttp provides a cleaner, more capable alternative. It is efficient by default in several important ways. It supports HTTP/2, a newer version of the protocol that allows multiple requests to the same server to share a single connection instead of opening a new one for each request, which significantly reduces latency. It uses connection pooling even for older HTTP/1.1 connections, automatically compresses responses using GZIP to reduce download sizes, and caches responses so repeat requests for the same data skip the network entirely. It handles real-world network reliability: if a server has multiple IP addresses (common for load-balanced services), OkHttp tries them in order on failure. It supports modern TLS security features including TLS 1.3 and certificate pinning. The API uses a builder pattern common in Java/Kotlin where you chain method calls to configure a request before sending it, and it supports both synchronous (blocking) and asynchronous (callback-based) request modes. You would use OkHttp in any Java or Kotlin application, including Android apps, that makes HTTP calls to web APIs, downloads files, or communicates with a backend server. It is the default HTTP client underlying many other popular Android libraries. It also includes a MockWebServer module for writing tests that simulate a real HTTP server without making actual network calls. The library is written in Kotlin and distributed via Maven Central.

Copy-paste prompts

Prompt 1
Show me how to make a simple GET request with OkHttp and handle the response in Kotlin.
Prompt 2
How do I set up OkHttp to cache API responses so repeated requests don't hit the network?
Prompt 3
Write a test using OkHttp's MockWebServer that simulates an API endpoint returning JSON.
Prompt 4
How do I configure OkHttp with certificate pinning to ensure my app only trusts specific SSL certificates?
Prompt 5
Show me how to make concurrent async requests with OkHttp and handle all responses together.
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.