SlideShare a Scribd company logo
1 of 32
Retrofit 2
Bruno Vieira
O que devemos saber
New Url Pattern
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
https://api.dribbble.com/shots?access_token=...
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
https://api.dribbble.com/v1/shots?access_token=...
New Url Pattern
Dynamic URL
public interface WebServiceApi{
@GET
Call<JokeVO> getAJoke(@Url String url);
}
Bippples
https://github.com/OBrunoVieira/Bippples
Dribbble
+
Chuck Norris Database
https://github.com/OBrunoVieira/Bippples
Bippples
https://github.com/OBrunoVieira/Bippples
OkHttp
OkHttp
Retrofit 1.9 - Is optional
Retrofit 2.x - Is required
Importing a specific version:
compile ('com.squareup.retrofit2:retrofit:2.0.2') {
exclude module: 'okhttp'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
OkHttp
Interceptors
public OkHttpClient clientInterceptor() {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(this);
...
return httpClient.build();
}
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
request = request.newBuilder()
.addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#")
.build();
return chain.proceed(request);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.client(clientInterceptor())
.build();
OkHttp
Interceptors
public OkHttpClient clientInterceptor() {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(this);
...
return httpClient.build();
}
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
request = request.newBuilder()
.addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#")
.build();
return chain.proceed(request);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.client(clientInterceptor())
.build();
OkHttp.Interceptors
No Logging
OkHttp.Interceptors
No Logging, but..
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
public OkHttpClient clientInterceptor() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(Environment.LOG_LEVEL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(interceptor);
...
return httpClient.build();
}
OkHttp.Interceptors
No Logging, but..
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
public OkHttpClient clientInterceptor() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(Environment.LOG_LEVEL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(interceptor);
...
return httpClient.build();
}
OkHttp.Interceptors
No Logging, but..
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
public OkHttpClient clientInterceptor() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(Environment.LOG_LEVEL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(interceptor);
...
return httpClient.build();
}
Converters
Converters
No converter by default
compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0"
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
Converters
No converter by default
compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0"
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
Requests
Requests
Synchronous and Asynchronous
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
List<ShotsVO> shotsList = call.execute.body;
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
...
}
Requests
Attention!
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
@Override
public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) {
...
}
}
https://github.com/OBrunoVieira/Bippples
Requests
Cancel
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
@Override
public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) {
...
}
}
call.cancel();
Requests
Cancel
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
@Override
public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) {
...
}
}
call.cancel();
=)
Source
http://square.github.io/retrofit/
https://inthecheesefactory.com/blog/retrofit-2.0/en
http://www.iayon.com/consuming-rest-api-with-retrofit-2-0-in-
android/
https://github.com/square/retrofit/blob/master/CHANGELOG.md
www.concretesolutions.com.br
blog.concretesolutions.com.br
Rio de Janeiro – Rua São José, 90 – cj. 2121
Centro – (21) 2240-2030
São Paulo - Rua Sansão Alves dos Santos, 433
4º andar - Brooklin - (11) 4119-0449

More Related Content

What's hot

Service Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C ZiegelerService Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C Ziegelermfrancis
 
Sensu wrapper-sensu-summit
Sensu wrapper-sensu-summitSensu wrapper-sensu-summit
Sensu wrapper-sensu-summitLee Briggs
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3Luciano Mammino
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testenndrssmn
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTDavid Chandler
 
HTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The DeadHTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The Deadnoamt
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Codenoamt
 
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech TalkContract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech TalkRed Hat Developers
 
Tdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyTdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyFabio Akita
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Andres Almiray
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Andres Almiray
 
Analysing Github events with Neo4j
Analysing Github events with Neo4jAnalysing Github events with Neo4j
Analysing Github events with Neo4jChristophe Willemsen
 
Salesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP calloutsSalesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP calloutsRAMNARAYAN R
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805t k
 
React native-firebase startup-mtup
React native-firebase startup-mtupReact native-firebase startup-mtup
React native-firebase startup-mtupt k
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitivesBartosz Sypytkowski
 
Spark Day 2017- Spark 의 과거, 현재, 미래
Spark Day 2017- Spark 의 과거, 현재, 미래Spark Day 2017- Spark 의 과거, 현재, 미래
Spark Day 2017- Spark 의 과거, 현재, 미래Moon Soo Lee
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 

What's hot (20)

Service Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C ZiegelerService Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C Ziegeler
 
Sensu wrapper-sensu-summit
Sensu wrapper-sensu-summitSensu wrapper-sensu-summit
Sensu wrapper-sensu-summit
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testen
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 
HTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The DeadHTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The Dead
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech TalkContract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
 
Tdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyTdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema Ruby
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
 
Analysing Github events with Neo4j
Analysing Github events with Neo4jAnalysing Github events with Neo4j
Analysing Github events with Neo4j
 
Salesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP calloutsSalesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP callouts
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
 
React native-firebase startup-mtup
React native-firebase startup-mtupReact native-firebase startup-mtup
React native-firebase startup-mtup
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
Spark Day 2017- Spark 의 과거, 현재, 미래
Spark Day 2017- Spark 의 과거, 현재, 미래Spark Day 2017- Spark 의 과거, 현재, 미래
Spark Day 2017- Spark 의 과거, 현재, 미래
 
Shibuya,trac セッション
Shibuya,trac セッションShibuya,trac セッション
Shibuya,trac セッション
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
NestJS
NestJSNestJS
NestJS
 

Viewers also liked

introduce Okhttp
introduce Okhttpintroduce Okhttp
introduce Okhttp朋 王
 
Simplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o RetrofitSimplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o RetrofitFelipe Pedroso
 
Android DevConference - Dagger 2: uso avançado em projetos Android
Android DevConference - Dagger 2: uso avançado em projetos AndroidAndroid DevConference - Dagger 2: uso avançado em projetos Android
Android DevConference - Dagger 2: uso avançado em projetos AndroidiMasters
 
Retro vs Volley
Retro vs VolleyRetro vs Volley
Retro vs VolleyArtjoker
 
Visteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisasVisteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisasJosé María Pérez Ramos
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
大鱼架构演进
大鱼架构演进大鱼架构演进
大鱼架构演进Jun Liu
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJavaJobaer Chowdhury
 
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃんRetrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃんYukari Sakurai
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Andres Almiray
 
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기Manjong Han
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & designallegro.tech
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Seismic retrofit methods
Seismic retrofit methodsSeismic retrofit methods
Seismic retrofit methodsPaul McMullin
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJosé Paumard
 

Viewers also liked (20)

Volley vs Retrofit
Volley vs RetrofitVolley vs Retrofit
Volley vs Retrofit
 
introduce Okhttp
introduce Okhttpintroduce Okhttp
introduce Okhttp
 
Simplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o RetrofitSimplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o Retrofit
 
Retrofit
RetrofitRetrofit
Retrofit
 
Realm @Android
Realm @Android Realm @Android
Realm @Android
 
Android DevConference - Dagger 2: uso avançado em projetos Android
Android DevConference - Dagger 2: uso avançado em projetos AndroidAndroid DevConference - Dagger 2: uso avançado em projetos Android
Android DevConference - Dagger 2: uso avançado em projetos Android
 
Retro vs Volley
Retro vs VolleyRetro vs Volley
Retro vs Volley
 
Visteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisasVisteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisas
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
大鱼架构演进
大鱼架构演进大鱼架构演进
大鱼架构演进
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃんRetrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Seismic retrofit methods
Seismic retrofit methodsSeismic retrofit methods
Seismic retrofit methods
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
 

Similar to Retrofit 2 - O que devemos saber

Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networkingVitali Pekelis
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC InternalsVitaly Baum
 
Implement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoImplement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoToshiaki Maki
 
Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xTatsuya Maki
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API IntroductionChris Love
 
CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCaelum
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicIMC Institute
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020Matt Raible
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Augemfrancis
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceNCCOMMS
 
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdfAPI 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdfssuserb6c2641
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxcelenarouzie
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...Fons Sonnemans
 
twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇twMVC
 
Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the networkMu Chun Wang
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftChris Bailey
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsLoiane Groner
 

Similar to Retrofit 2 - O que devemos saber (20)

Web api's
Web api'sWeb api's
Web api's
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC Internals
 
Servlets
ServletsServlets
Servlets
 
Implement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoImplement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyo
 
Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.x
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API Introduction
 
Android dev 3
Android dev 3Android dev 3
Android dev 3
 
CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptor
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
 
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdfAPI 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
 
twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇
 
Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the network
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) Swift
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
 

Recently uploaded

Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationMarko4394
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 

Recently uploaded (20)

Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentation
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 

Retrofit 2 - O que devemos saber

  • 1. Retrofit 2 Bruno Vieira O que devemos saber
  • 3. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 4. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 5. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 6. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } } https://api.dribbble.com/shots?access_token=...
  • 7. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 8. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 9. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 10. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } } https://api.dribbble.com/v1/shots?access_token=...
  • 11. New Url Pattern Dynamic URL public interface WebServiceApi{ @GET Call<JokeVO> getAJoke(@Url String url); }
  • 15. OkHttp Retrofit 1.9 - Is optional Retrofit 2.x - Is required Importing a specific version: compile ('com.squareup.retrofit2:retrofit:2.0.2') { exclude module: 'okhttp' } compile 'com.squareup.okhttp3:okhttp:3.2.0'
  • 16. OkHttp Interceptors public OkHttpClient clientInterceptor() { OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(this); ... return httpClient.build(); } public Response intercept(Chain chain) throws IOException { Request request = chain.request(); request = request.newBuilder() .addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#") .build(); return chain.proceed(request); } Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .client(clientInterceptor()) .build();
  • 17. OkHttp Interceptors public OkHttpClient clientInterceptor() { OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(this); ... return httpClient.build(); } public Response intercept(Chain chain) throws IOException { Request request = chain.request(); request = request.newBuilder() .addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#") .build(); return chain.proceed(request); } Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .client(clientInterceptor()) .build();
  • 19. OkHttp.Interceptors No Logging, but.. compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' public OkHttpClient clientInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(Environment.LOG_LEVEL); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(interceptor); ... return httpClient.build(); }
  • 20. OkHttp.Interceptors No Logging, but.. compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' public OkHttpClient clientInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(Environment.LOG_LEVEL); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(interceptor); ... return httpClient.build(); }
  • 21. OkHttp.Interceptors No Logging, but.. compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' public OkHttpClient clientInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(Environment.LOG_LEVEL); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(interceptor); ... return httpClient.build(); }
  • 23. Converters No converter by default compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0" Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build();
  • 24. Converters No converter by default compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0" Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build();
  • 26. Requests Synchronous and Asynchronous Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); List<ShotsVO> shotsList = call.execute.body; Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } ... }
  • 27. Requests Attention! Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } @Override public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) { ... } } https://github.com/OBrunoVieira/Bippples
  • 28. Requests Cancel Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } @Override public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) { ... } } call.cancel();
  • 29. Requests Cancel Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } @Override public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) { ... } } call.cancel();
  • 30. =)
  • 32. www.concretesolutions.com.br blog.concretesolutions.com.br Rio de Janeiro – Rua São José, 90 – cj. 2121 Centro – (21) 2240-2030 São Paulo - Rua Sansão Alves dos Santos, 433 4º andar - Brooklin - (11) 4119-0449