Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Retrofit Two Recap
Search
punchdrunker
September 11, 2015
Programming
450
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Retrofit Two Recap
punchdrunker
September 11, 2015
More Decks by punchdrunker
See All by punchdrunker
Kotlin2.0以降の新機能
punchdrunker
0
48
DnD in Compose
punchdrunker
0
320
what's new in Material Design で気になったトピック
punchdrunker
1
650
7カ国語に対応したサービスでの翻訳管理システムの改善事例
punchdrunker
1
1.5k
Java Bytecode Vertical Tasting
punchdrunker
2
1.6k
getting started with dark theme
punchdrunker
2
1.1k
Practical Activity Transition in Android
punchdrunker
0
1.3k
今時のProgress indicator / Replacing ProgressDialog with ProgressBar
punchdrunker
0
740
レビュー評価4.7の秘密 / The Secret To A Better Reputation
punchdrunker
2
2.1k
Other Decks in Programming
See All in Programming
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
220
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
130
dRuby over BLE
makicamel
2
330
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
500
RTSPクライアントを自作してみた話
simotin13
0
590
ふつうのFeature Flag実践入門
irof
7
3.7k
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
390
さぁV100、メモリをお食べ・・・
nilpe
0
140
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
330
技術記事、 専門家としてのプログラマ、 言語化
mizchi
12
4.6k
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
200
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
320
Optimising Largest Contentful Paint
csswizardry
37
3.7k
Building an army of robots
kneath
306
46k
Odyssey Design
rkendrick25
PRO
2
690
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
280
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Transcript
Retrofit Two Recap @punchdruneker
• engineer at mixi, Inc • sidelines • DroidKaigi •
teaching at schoo • Shibuya.apk • and so on… @punchdrunker
None
Retrofit 2 beta released!
Retrofit 2 way public interface GitHub { @GET("/repos/{owner}/{repo}/contributors") Call<List<Contributor>> contributors(
@Path("owner") Owner owner, @Path("repo") String repo); @GET Call<List<Contributor>> contributorsPaginate( @Url String url); } Parameter Type Dynamic Url
Setup Retrofit retrofit = new Retrofit.Builder() .baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); GitHub
github = retrofit.create(GitHub.class); Owner square = new Owner(“square"); Call<List<Contributor>> call = github.contributors(square, "retrofit"); Multiple Converter Call encapsulates single request/response interaction
Asynchronous execution call.enqueue(new Callback<List<Contributor>>() { @Override public void onResponse(Response<List<Contributor>> response)
{ // Log.d(response.headers().toString()); // Log.d(response.raw()); // => okhttp/Response List<Contributor> contributors = response.body(); for (Contributor contributor : contributors) { Log.d(contributor.login + " (" + contributor.contributions + ")"); } } ….
Asynchronous execution call.enqueue(new Callback<List<Contributor>>() { @Override public void onResponse(Response<List<Contributor>> response)
{ // Log.d(response.headers().toString()); // Log.d(response.raw()); // => okhttp/Response List<Contributor> contributors = response.body(); for (Contributor contributor : contributors) { Log.d(contributor.login + " (" + contributor.contributions + ")"); } } …. Parameterized Response Object
Call (Class) • Models a single request/response pair • Separates
request creation from response handling • Each instance can only be used once... • ...instances can be cloned • Supports both synchronous and asynchronous execution. • Can be (actually) canceled
Multiple Converter // We can user multiple converters public interface
AwesomeService { @GET("/awesome/proto/endpoint") Call<ProtoResponse> awesomeProtoEndpoint(); @GET("/awesome/json/endpoint") Call<JsonResponse> awesomeJsonEndpoint(); } ————————————————————————————————————————————- Retrofit retrofitMulti = new Retrofit.Builder() .baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(ProtoConverterFactory.create()) .build();
Multiple execution mechanism public interface GreatService { @GET("/repos/{owner}/{repo}/contributors") Call<List<Contributor>> repoContributors(
@Path("owner") String owner, @Path("repo") String repo); @GET("/repos/{owner}/{repo}/contributors") Observable<List<Contributor>> repoContributors2( @Path("owner") String owner, @Path("repo") String repo); @GET("/repos/{owner}/{repo}/contributors") Future<List<Contributor>> repoContributors3( @Path("owner") String owner, @Path("repo") String repo); }
Multiple execution mechanism public interface GreatService { @GET("/repos/{owner}/{repo}/contributors") Call<List<Contributor>> repoContributors(
@Path("owner") String owner, @Path("repo") String repo); @GET("/repos/{owner}/{repo}/contributors") Observable<List<Contributor>> repoContributors2( @Path("owner") String owner, @Path("repo") String repo); @GET("/repos/{owner}/{repo}/contributors") Future<List<Contributor>> repoContributors3( @Path("owner") String owner, @Path("repo") String repo); }
Pluggable execution mechanism Retrofit retrofit = new Retrofit.Builder() .baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build();
Pluggable execution mechanism Retrofit retrofit = new Retrofit.Builder() .baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build();
Future • Parameter handlers • Logging? • Finalizing mock module
• Documentation • WebSockets!(in v2.1)
more info • Simple HTTP with retrofit2 • https://www.youtube.com/watch? v=KIAoQbAu3eA
• sample code • https://github.com/punchdrunker/ Retrofit2Sample
Thank you!