Retrofit integrationΒΆ

Retrofit is a library that simplifies the access to RESTful services by turning an HTTP API into a Java interface.

Armeria provides a builder class called ArmeriaRetrofitBuilder that builds an alternative Retrofit implementation that replaces the networking engine of from OkHttp to Armeria. By doing so, you get the following benefits:

  • Better performance, thanks to Netty and its JNI-based I/O and TLS implementation

  • Leverage other advanced features of Armeria, such as client-side load-balancing and service discovery

  • Cleartext HTTP/2 support, as known as h2c

import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Path;

class UserInfo { ... }

interface MyService {
    CompletableFuture<UserInfo> getUserInfo(@Path("id") String id);

Retrofit retrofit = new ArmeriaRetrofitBuilder()

MyService service = retrofit.create(MyService.class);
UserInfo userInfo = service.getUserInfo("foo").get();

For more information, please refer to the API documentation of the com.linecorp.armeria.client.retrofit2 package.