explaingit

square/retrofit

📈 Trending43,906HTMLAudience · developerComplexity · 2/5ActiveLicenseSetup · easy

TLDR

Type-safe HTTP client for Java and Android that turns REST APIs into simple interfaces, letting your IDE catch mistakes before you run the code.

Mindmap

mindmap
  root((Retrofit))
    What it does
      Describes APIs as interfaces
      Generates HTTP implementations
      Handles serialization
    Key features
      Type-safe method calls
      IDE autocomplete support
      Compiler error checking
    Data formats
      JSON via Gson/Jackson/Moshi
      Protobuf and XML
    Async patterns
      RxJava integration
      Kotlin coroutines
      Java Futures
    Use cases
      Android app development
      Backend service clients
      REST API consumption

Things people build with this

USE CASE 1

Build Android apps that fetch data from REST APIs without manually constructing HTTP requests.

USE CASE 2

Create backend services that call third-party APIs with type-safe method calls and compile-time error checking.

USE CASE 3

Consume JSON or XML APIs with automatic serialization and deserialization using your choice of format library.

USE CASE 4

Handle asynchronous API calls using RxJava, coroutines, or Futures depending on your project's concurrency needs.

Tech stack

JavaKotlinOkHttpGsonJacksonMoshiRxJavaProtobuf

Getting it running

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

In plain English

Retrofit is a type-safe HTTP client library for Android and the Java Virtual Machine (JVM), developed and open-sourced by Square. The problem it solves is making REST API calls in Java and Android cleaner and safer. Without a library like Retrofit, calling a web API requires manually constructing URLs, building HTTP requests, sending them, parsing the raw JSON or XML response, and handling errors, all low-level, repetitive, and error-prone work. Retrofit lets you describe your entire API as a Java or Kotlin interface using annotations. Each method in the interface represents one API endpoint: you annotate it with the HTTP method and URL path, annotate the parameters to indicate which become URL segments, query parameters, or request body fields, and specify the return type. Retrofit then generates the actual implementation of that interface at runtime, handling URL construction, serialization, and deserialization automatically. Because the API contract is expressed as a regular Java/Kotlin interface with typed method signatures, your IDE can autocomplete method calls and your compiler can catch mistakes, for example, passing the wrong type of argument or forgetting a required parameter, before you ever run the code. This is what "type-safe" means in this context. Retrofit works with multiple serialization backends (converters) to handle different data formats: Gson, Jackson, Moshi, and others for JSON, as well as Protobuf and XML. For asynchronous calls it integrates with RxJava, Kotlin coroutines, and Java Futures, so you can choose the concurrency model that fits your project. Networking is built on top of Square's OkHttp library. Android developers and backend Java/Kotlin service developers reach for Retrofit whenever they need to consume a REST API. It is one of the most widely adopted networking libraries in the Android ecosystem. It requires Java 8 or newer, or Android API level 21 and above. It is distributed via Maven Central and licensed under Apache 2.0.

Copy-paste prompts

Prompt 1
Show me how to define a GitHub API client interface with Retrofit that fetches user repositories with type-safe method signatures.
Prompt 2
How do I configure Retrofit to use Gson for JSON deserialization and OkHttp for networking in my Android app?
Prompt 3
Create a Retrofit service interface for a weather API that accepts latitude/longitude as query parameters and returns typed response objects.
Prompt 4
How do I make asynchronous API calls with Retrofit using Kotlin coroutines instead of callbacks?
Prompt 5
Show me how to add custom interceptors to Retrofit for logging and authentication headers.
Open on GitHub → Explain another repo

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