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
58
DnD in Compose
punchdrunker
0
340
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
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
500
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
320
React本体のコードリーディング
high_g_engineer
1
120
Built Our Own Background Agent at LayerX #aidevex_findy
layerx
PRO
9
4.3k
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.4k
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
360
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1.1k
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
160
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
3.3k
AIが無かった頃の素敵な出会いの話
codmoninc
1
340
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
190
メールのエイリアス機能を履き違えない
isshinfunada
0
190
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
3
3.5k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
Mind Mapping
helmedeiros
PRO
1
290
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
420
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Designing Experiences People Love
moore
143
24k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
550
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
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!