Introduction
Retrofit turns your HTTP API into a Java (or Kotlin) interface.
public interface Service { @GET("users/{user}/repos") Call<List<Repo>> listRepos(@Path("user") String user);}
The Retrofit
class generates an implementation of the Service
interface.
Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api..com") .build();
Service service = retrofit.create(Service.class);
Each Call
from the created Service
can make synchronous or asynchronous HTTP requests to the remote webserver.
Call<List<Repo>> repos = service.listRepos("octocat");
Use annotations to describe the HTTP request on each interface method:
- URL parameter replacement and query parameter support
- Object conversion to request body (e.g., JSON, protocol buffers)
- Multipart request body and file upload