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
330
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
CSC307 Lecture 17
javiergs
PRO
0
320
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.1k
Webフレームワークの ベンチマークについて
yusukebe
0
170
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
230
RTSPクライアントを自作してみた話
simotin13
0
600
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
130
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
400
ふつうのFeature Flag実践入門
irof
7
3.9k
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
550
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
120
Featured
See All Featured
Claude Code のすすめ
schroneko
67
230k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
160
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
Designing for humans not robots
tammielis
254
26k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
710
How to Talk to Developers About Accessibility
jct
2
230
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Skip the Path - Find Your Career Trail
mkilby
1
150
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!