Retrofit is the de-facto HTTP client for native Android. It turns a REST API into a type-safe Kotlin interface, handles serialization, and integrates cleanly with coroutines. Even in a React Native app, you reach for it when a native module needs to talk to a backend off the JS thread.

Key takeaways

  • Describe endpoints as a typed Kotlin interface; Retrofit generates the implementation.
  • Use suspend functions so calls run on coroutines with structured cancellation.
  • Centralize converters, interceptors, and error handling in one OkHttp client.

Type-safe API definitions

With Retrofit you declare an interface where each method maps to an endpoint via annotations (GET, POST, path, query, body). Retrofit builds the networking code for you, and a converter such as Moshi or Kotlinx Serialization turns JSON into data classes, so the rest of your app works with typed models instead of raw responses.

This eliminates a whole category of stringly-typed bugs and makes API changes show up as compile errors rather than runtime crashes.

Coroutines and error handling

Declaring API methods as suspend functions lets you call them from a coroutine scope and get structured concurrency — cancellation propagates when the screen goes away. Wrap calls in a try/catch (or a Result wrapper) and inspect HTTP status to distinguish network failures, server errors, and validation responses.

Configure the underlying OkHttp client once with timeouts, logging, and an auth interceptor that attaches tokens, so every request behaves consistently.

Where it fits with React Native

In a React Native app you usually fetch from JavaScript, but when a native module performs background work — a sync job, a headless task, or a foreground service — Retrofit is the clean way for that Kotlin code to reach your API without involving the JS bridge.