← All open source projects

Retrofit

square/retrofit

Retrofit is Square’s type-safe HTTP client for Android and the JVM, built around interfaces, annotations, and converters.

Forks 7,337
Author square
Language HTML
License Apache-2.0
Synced 2026-06-27

What it is

Retrofit is an HTTP client for Android and the JVM that turns API descriptions into type-safe calls. Instead of manually building URLs and parsing responses, the developer describes a service as an interface.

The project appeared in Square’s ecosystem near OkHttp and solves a neighboring task: OkHttp handles the network layer, while Retrofit describes the application HTTP API neatly.

Retrofit’s main task is to connect annotations, parameters, response-body converters, and call adapters so client code stays readable.

What is inside

Inside the project are the library, website documentation, Maven coordinates `com.squareup.retrofit2:retrofit`, Java 8+ and Android API 21+ support, and R8/ProGuard notes.

Retrofit is usually used with JSON converters and OkHttp. The service interface becomes a contract between the app and the server.

How people use it

A normal scenario is to describe API methods, paths, and parameters, create a Retrofit instance, and call methods from an app data repository.

For Android, this is especially useful because network code stops spreading across screens and becomes a separate layer that is easier to test and change.

Example

Describing an HTTP API as an interface

This example shows Retrofit’s main idea: an endpoint is described as an interface method, and the library builds the call from annotations.

Language: Plain text
interface GitHubService {
  @GET("users/{user}/repos")
  suspend fun listRepos(@Path("user") user: String): List<Repo>
}

Strengths

The project’s strength is clarity. By reading the interface, it is easy to see which requests the app makes and which data types it expects.

Another advantage is the mature pairing with OkHttp, interceptors, logging, authentication, and cache. Retrofit does not replace network policy; it keeps the API layer tidy.

Limitations

The limitation is that type safety does not fix a bad contract. Server schema mistakes, unstable fields, and unclear statuses need separate handling.

It is also important not to turn one Retrofit interface into a huge pile of endpoints. Large apps should split services by domain area.

Who it fits

Retrofit fits Android and JVM teams that need a clear HTTP API layer on top of a reliable network client.

For one tiny request, direct OkHttp may be enough, but as the API grows, the interface approach pays off quickly.

In the catalog, Retrofit matters as a library that shaped a very familiar networking style in the Android world.

A practical start is to describe one service, connect a JSON converter, add error handling, and only then expand the client to the rest of the API.

In a real Android app, Retrofit is especially useful beside a clear error model. The team decides which responses become exceptions, where tokens are refreshed, how failures are logged, and which data types are treated as a stable contract.