Retrofit 2.0
KRISTIJAN JURKOVIC
WHAT IS RETROFIT?
USAGE
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
WHAT’S DIFFERENT?
com.squareup.retrofit > com.squareup.retrofit2
Converters
Rest interface methods return Call<T>
OkHttp is required
Security exception if no Internet permission
RestAdapter > Retrofit
CALL<T>
call.enqueue(new Callback<T> { … })
call.execute();
call.cancel();
ONRESPONSE
response.isSuccess();
response.code();
response.body();
response.errorBody().string();
URL HANDLING
same as web <a href=“…” /> handling
@GET(“blog”)
Base url: http://www.infinum.co/api/v1
Result: http://www.infinum.co/api/blog
Base url: http://www.infinum.co/api/v1/
Result: http://www.infinum.co/api/v1/blog
URL HANDLING
@GET(“/blog”)
Base url: http://www.infinum.co/api/v1
Result: http://www.infinum.co/blog
@GET(“http://www.infinum.co/api/v1/blog”)
@GET
void get(@Url String url);
LOG
CONVERTERS
.addConverterFactory({pass in converter here});
Gson: com.squareup.retrofit:converter-gson
Jackson: com.squareup.retrofit:converter-jackson
Moshi: com.squareup.retrofit:converter-moshi
Protobuf: com.squareup.retrofit:converter-protobuf
Wire: com.squareup.retrofit:converter-wire
Simple XML: com.squareup.retrofit:converter-simplexml
Converter.Factory interface
CONVERTERS
.addConverterFactory({pass in converter here});
Gson gson = new GsonBuilder()
... add type converters here
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(“http://www.infinum.co/api/”)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
Any questions?
KRISTIJAN.JURKOVIC@INFINUM.CO
@KJURKOVIC
Visit infinum.co or find us on social networks:
infinum.co infinumco infinumco infinum

Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic