SlideShare a Scribd company logo
1 of 15
Download to read offline
Introduction to Retrofit
or how to say goodbye to
almost correct API doc
第十一回 #渋谷java
Kazuhiro Serizawa
About me
• Name: Kazuhiro Serizawa
• Job: Web engineer
• Like: RoR, AngularJS
• Github: serihiro
• Twitter: seri_k
• Blog: http://serihiro.hatenablog.com/
What is Retrofit?
• A type-safe REST client for Android and Java
• Created by Square, Inc.
• 5493 Starred (at 2015.5.25)
• Latest version is 1.9.0 (at 2015.5.25)
• Gtihub: https://github.com/square/retrofit
• Docs: http://square.github.io/retrofit/
How to use?
In the case you access to Todo API
GET /todo … response todo list with json
GET /todo/:id … response todo with json
POST /todo … create new todo resource
code sample
https://github.com/serihiro/retrofit-implement-samle
1. Define API Interface
public interface TodoService {
@GET("/todos")
List<Todo> list();
@GET("/todos/{id}")
Todo show(@Path("id") Integer id);
@POST("/todos")
void create(@Body Todo todo);
}
2. Implement model class
for API response
public class Todo {
public Integer id = null;
public String todo = "";
public boolean done = false;
public Todo(String todo, boolean done) {
this.todo = todo;
this.done = done;
}
}
3. Generate implementation
for API interface
RestAdapter restAdapter = new
RestAdapter.Builder()
.setEndpoint( http://localhost:3000")
.build();

TodoService todoService =
restAdapter.create(TodoService.class);
4.call api
List<Todo> todos = todoService.list();
Todo todo = todoService.show(1);
todoService.create(new Todo( drink beer , false));
Typesafe
• Define endpoints as method
• So rest client with Retrofit knows what
endpoints API has
Interface as API
Specification
• Client user can know what endpoint exists
• User get 404 with wrong endpoint name spell !!!
• No more almost correct API documents : )
public interface TodoService {

@GET("/todos")

List<Todo> list();

@GET("/todos/{id}")

Todo show(@Path("id") int id);

@POST("/todos")

void create(@Body Todo todo, Callback<Result> cb);

}
feature: ASYNC request
with callback
• Synchronous
• void create(@Body Todo todo)
• Asynchronous
• void create(@Body Todo todo,
Callback<Result> cb);
converters
Retrofit uses Gson to parse response body as a
default.

There are following converter class instead of Gson;
• Simple XML Parser(Uses simple framework)
• Jackson
• Google Protocol Buffer
• Wire
source: https://github.com/square/retrofit/tree/master/retrofit-converters
feature: static/dynamic
header value
Static Header

@Headers({

"Accept: application/vnd.github.v3.full+json ,

"User-Agent: Retrofit-Sample-App"

})

@GET("/todos")

List<Todo> list();
feature: static/dynamic
header value
Dynamic Header


@GET("/todos")

List<Todo> list(@Header("Authorization")
String authorization);
Conclusion
Retrofit provides
no more

almost correct 

api-document life :)

More Related Content

What's hot

WuKong - Framework for Integrated Test
WuKong - Framework for Integrated TestWuKong - Framework for Integrated Test
WuKong - Framework for Integrated Test
Summer Lu
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)
Nordic APIs
 
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Atlassian
 

What's hot (20)

Django rest framework tips and tricks
Django rest framework   tips and tricksDjango rest framework   tips and tricks
Django rest framework tips and tricks
 
WuKong - Framework for Integrated Test
WuKong - Framework for Integrated TestWuKong - Framework for Integrated Test
WuKong - Framework for Integrated Test
 
Spring Bootを触ってみた
Spring Bootを触ってみたSpring Bootを触ってみた
Spring Bootを触ってみた
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Spring Booted, But... @JCConf 16', Taiwan
Spring Booted, But... @JCConf 16', TaiwanSpring Booted, But... @JCConf 16', Taiwan
Spring Booted, But... @JCConf 16', Taiwan
 
StirTrek 2018 - Rapid API Development with Sails
StirTrek 2018 - Rapid API Development with SailsStirTrek 2018 - Rapid API Development with Sails
StirTrek 2018 - Rapid API Development with Sails
 
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CIPython Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
 
Writing documentation with Asciidoctor
Writing documentation  with  AsciidoctorWriting documentation  with  Asciidoctor
Writing documentation with Asciidoctor
 
Git training
Git trainingGit training
Git training
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)
 
Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)
 
API Design & Security in django
API Design & Security in djangoAPI Design & Security in django
API Design & Security in django
 
Git Workshop
Git WorkshopGit Workshop
Git Workshop
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 
Workshop 15: Ionic framework
Workshop 15: Ionic frameworkWorkshop 15: Ionic framework
Workshop 15: Ionic framework
 
PWA 與 Service Worker
PWA 與 Service WorkerPWA 與 Service Worker
PWA 與 Service Worker
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 

Viewers also liked

Viewers also liked (9)

UXデザインワークショップ資料 by ATOMOS DESIGN
UXデザインワークショップ資料 by ATOMOS DESIGNUXデザインワークショップ資料 by ATOMOS DESIGN
UXデザインワークショップ資料 by ATOMOS DESIGN
 
AWS Lambda with Java/Scala #渋谷Java 第十二回
AWS Lambda with Java/Scala #渋谷Java 第十二回AWS Lambda with Java/Scala #渋谷Java 第十二回
AWS Lambda with Java/Scala #渋谷Java 第十二回
 
SFA運用の秘訣と定着化のコツセミナー資料
SFA運用の秘訣と定着化のコツセミナー資料SFA運用の秘訣と定着化のコツセミナー資料
SFA運用の秘訣と定着化のコツセミナー資料
 
Hello, Type Systems! - Introduction to Featherweight Java
Hello, Type Systems! - Introduction to Featherweight JavaHello, Type Systems! - Introduction to Featherweight Java
Hello, Type Systems! - Introduction to Featherweight Java
 
カスタマーサポートだからこそ提供できる価値とは?(CS Night -ネット企業のカスタマーサポート戦略を考えよう! -)
カスタマーサポートだからこそ提供できる価値とは?(CS Night -ネット企業のカスタマーサポート戦略を考えよう! -)カスタマーサポートだからこそ提供できる価値とは?(CS Night -ネット企業のカスタマーサポート戦略を考えよう! -)
カスタマーサポートだからこそ提供できる価値とは?(CS Night -ネット企業のカスタマーサポート戦略を考えよう! -)
 
Javaの資格試験(OCJ-P)を取って何を学んだか
Javaの資格試験(OCJ-P)を取って何を学んだかJavaの資格試験(OCJ-P)を取って何を学んだか
Javaの資格試験(OCJ-P)を取って何を学んだか
 
Adaptive Path's Guide To Experience Mapping (Japanese Edition)
Adaptive Path's Guide To Experience Mapping (Japanese Edition)Adaptive Path's Guide To Experience Mapping (Japanese Edition)
Adaptive Path's Guide To Experience Mapping (Japanese Edition)
 
僕とメロス 第零章~第弐章
僕とメロス 第零章~第弐章僕とメロス 第零章~第弐章
僕とメロス 第零章~第弐章
 
リクルート式 自然言語処理技術の適応事例紹介
リクルート式 自然言語処理技術の適応事例紹介リクルート式 自然言語処理技術の適応事例紹介
リクルート式 自然言語処理技術の適応事例紹介
 

Similar to Introduction to Retrofit

AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...
AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...
AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...
Amazon Web Services
 
Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
Liam Cleary [MVP]
 

Similar to Introduction to Retrofit (20)

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
 
Test-Driven Documentation for your REST(ful) service
Test-Driven Documentation for your REST(ful) serviceTest-Driven Documentation for your REST(ful) service
Test-Driven Documentation for your REST(ful) service
 
Extending Retrofit for fun and profit
Extending Retrofit for fun and profitExtending Retrofit for fun and profit
Extending Retrofit for fun and profit
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
Build REST API clients for AngularJS
Build REST API clients for AngularJSBuild REST API clients for AngularJS
Build REST API clients for AngularJS
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Tips and Tricks for Building Visual Studio Workflows
Tips and Tricks for Building Visual Studio WorkflowsTips and Tricks for Building Visual Studio Workflows
Tips and Tricks for Building Visual Studio Workflows
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
AWS July Webinar Series: Overview: Build and Manage your APIs with Amazon API...
AWS July Webinar Series: Overview: Build and Manage your APIs with Amazon API...AWS July Webinar Series: Overview: Build and Manage your APIs with Amazon API...
AWS July Webinar Series: Overview: Build and Manage your APIs with Amazon API...
 
AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...
AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...
AWS July Webinar Series - Overview Build and Manage your APs with amazon api ...
 
SharePoint 2013 REST APIs
SharePoint 2013 REST APIsSharePoint 2013 REST APIs
SharePoint 2013 REST APIs
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
SharePoint 2013 APIs
SharePoint 2013 APIsSharePoint 2013 APIs
SharePoint 2013 APIs
 
Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
 
Developing on the aloashbei platform
Developing on the aloashbei platformDeveloping on the aloashbei platform
Developing on the aloashbei platform
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 

More from Kazuhiro Serizawa

More from Kazuhiro Serizawa (10)

Rubyはとても「人間的」
Rubyはとても「人間的」Rubyはとても「人間的」
Rubyはとても「人間的」
 
第八回 #渋谷Java 最近のjava PaaS事情
第八回 #渋谷Java 最近のjava PaaS事情第八回 #渋谷Java 最近のjava PaaS事情
第八回 #渋谷Java 最近のjava PaaS事情
 
第六回 #渋谷java Javaを書き始めて 1年半が経って思うこと
第六回 #渋谷java Javaを書き始めて 1年半が経って思うこと第六回 #渋谷java Javaを書き始めて 1年半が経って思うこと
第六回 #渋谷java Javaを書き始めて 1年半が経って思うこと
 
第四回 #渋谷java オープニング
第四回 #渋谷java オープニング第四回 #渋谷java オープニング
第四回 #渋谷java オープニング
 
Juzu Frameworkを使ってみた @第四回 渋谷java
Juzu Frameworkを使ってみた @第四回 渋谷javaJuzu Frameworkを使ってみた @第四回 渋谷java
Juzu Frameworkを使ってみた @第四回 渋谷java
 
第3回渋谷javaオープニング
第3回渋谷javaオープニング第3回渋谷javaオープニング
第3回渋谷javaオープニング
 
第二回渋谷Java Opening #渋谷Java
第二回渋谷Java Opening #渋谷Java第二回渋谷Java Opening #渋谷Java
第二回渋谷Java Opening #渋谷Java
 
じっくりコトコト煮込んだJavaスープ
じっくりコトコト煮込んだJavaスープじっくりコトコト煮込んだJavaスープ
じっくりコトコト煮込んだJavaスープ
 
PHPerがJava屋になるために乗り越えたこと
PHPerがJava屋になるために乗り越えたことPHPerがJava屋になるために乗り越えたこと
PHPerがJava屋になるために乗り越えたこと
 
第一回Shibuya.javaオープニング
第一回Shibuya.javaオープニング第一回Shibuya.javaオープニング
第一回Shibuya.javaオープニング
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Introduction to Retrofit

  • 1. Introduction to Retrofit or how to say goodbye to almost correct API doc 第十一回 #渋谷java Kazuhiro Serizawa
  • 2. About me • Name: Kazuhiro Serizawa • Job: Web engineer • Like: RoR, AngularJS • Github: serihiro • Twitter: seri_k • Blog: http://serihiro.hatenablog.com/
  • 3. What is Retrofit? • A type-safe REST client for Android and Java • Created by Square, Inc. • 5493 Starred (at 2015.5.25) • Latest version is 1.9.0 (at 2015.5.25) • Gtihub: https://github.com/square/retrofit • Docs: http://square.github.io/retrofit/
  • 4. How to use? In the case you access to Todo API GET /todo … response todo list with json GET /todo/:id … response todo with json POST /todo … create new todo resource code sample https://github.com/serihiro/retrofit-implement-samle
  • 5. 1. Define API Interface public interface TodoService { @GET("/todos") List<Todo> list(); @GET("/todos/{id}") Todo show(@Path("id") Integer id); @POST("/todos") void create(@Body Todo todo); }
  • 6. 2. Implement model class for API response public class Todo { public Integer id = null; public String todo = ""; public boolean done = false; public Todo(String todo, boolean done) { this.todo = todo; this.done = done; } }
  • 7. 3. Generate implementation for API interface RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint( http://localhost:3000") .build();
 TodoService todoService = restAdapter.create(TodoService.class);
  • 8. 4.call api List<Todo> todos = todoService.list(); Todo todo = todoService.show(1); todoService.create(new Todo( drink beer , false));
  • 9. Typesafe • Define endpoints as method • So rest client with Retrofit knows what endpoints API has
  • 10. Interface as API Specification • Client user can know what endpoint exists • User get 404 with wrong endpoint name spell !!! • No more almost correct API documents : ) public interface TodoService {
 @GET("/todos")
 List<Todo> list();
 @GET("/todos/{id}")
 Todo show(@Path("id") int id);
 @POST("/todos")
 void create(@Body Todo todo, Callback<Result> cb);
 }
  • 11. feature: ASYNC request with callback • Synchronous • void create(@Body Todo todo) • Asynchronous • void create(@Body Todo todo, Callback<Result> cb);
  • 12. converters Retrofit uses Gson to parse response body as a default.
 There are following converter class instead of Gson; • Simple XML Parser(Uses simple framework) • Jackson • Google Protocol Buffer • Wire source: https://github.com/square/retrofit/tree/master/retrofit-converters
  • 13. feature: static/dynamic header value Static Header
 @Headers({
 "Accept: application/vnd.github.v3.full+json ,
 "User-Agent: Retrofit-Sample-App"
 })
 @GET("/todos")
 List<Todo> list();
  • 14. feature: static/dynamic header value Dynamic Header 
 @GET("/todos")
 List<Todo> list(@Header("Authorization") String authorization);
  • 15. Conclusion Retrofit provides no more
 almost correct 
 api-document life :)