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
51
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
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
160
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
7
2.9k
Vite+ Unified Toolchain for the Web
naokihaba
0
700
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.3k
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
180
Contextとはなにか
chiroruxx
1
390
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
290
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
210
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
130
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
350
dRuby over BLE
makicamel
2
410
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1.1k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
150
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
330
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
760
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
Tell your own story through comics
letsgokoyo
1
990
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Ruling the World: When Life Gets Gamed
codingconduct
0
270
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
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!