Upload
infinum
View
269
Download
1
Embed Size (px)
Citation preview
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();
ONRESPONSEresponse.isSuccess();
response.code();
response.body();
response.errorBody().string();
URL HANDLINGsame 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-gsonJackson: com.squareup.retrofit:converter-jacksonMoshi: com.squareup.retrofit:converter-moshiProtobuf: com.squareup.retrofit:converter-protobufWire: com.squareup.retrofit:converter-wireSimple 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? KRISTIJ[email protected] @KJURKOVIC
Visit infinum.co or find us on social networks:
infinum.co infinumco infinumco infinum