SlideShare a Scribd company logo
The Lazy Programmers Guide to Consuming Web
Services (in Android)
Max Bhuiyan http://au.linkedin.com/in/mamnun
Ben Kenny http://au.linkedin.com/pub/ben-kenny/3a/b9a/b67
Disclaimer
These slides are available under the Creative
Commons Attribution-ShareAlike (BY-SA) 3.0
License.
Trademarks and brands are the property of their respective
owners.
This presentation is not affiliated with Yahoo, Yahoo7 or Seven
Media.
Web API integration challenges
● Authentication
● Response
deserialization
● Caching
● Unreliable Network
Android specific challenges
● Network calls on background thread
o Async Tasks
o Loader
o Service/Daemon
● Response Processing : CPU + Memory
constraint
No network, No problem
Standing on the
shoulders of
giants
● RoboSpice
● Jackson
● JSONPath
● Retrofit
● OkHttp
● Signpost
: Cache Manager
● Uses an AndroidService to execute network
requests in background
● Plugin Architecture
● Supports request queue & prioritization
● Per request caching policy
● Handles activity/fragment lifecycle
Jackson : JSON Processor
● FAST!!!
● Streaming parser
● Easy annotation
based mapping
● Handles
polymorphic
types(more about
this from Ben)
RetrofitRetrofit
● Super simple API definition
o 2 lines to define an endpoint
o 1 class with 3 functions to code the Request
● Uses OkHttp(uses nio)
Overview
Thanks for listening.
Have a potato :)
He who controls the spice, controls the universe!
-- Baron Harkonnen
Quick example - Github Keys API
$ curl -i https://api.github.com/users/snookle/keys
[
{
"id": 8050932,
"key": "ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQC6lev8ySCrH9IIysnPsgpNyVcPomAM/n
Gn2nC8Cx4y5ttL5K9C5He1qkw7QQW5jTDsgtdYhS5u46CvKQFzrFLcdffkEJP1
dsnR1y+PWgzpXA81xvGFrOlYBtGh3n9Iuh7z5pw2WEBXnTqLkAmDtozFkJ0uJb
0bUnIc2mVRj9noCk5/dGKnzIweKpxaMpSWhR7I46lrAWlKE1sX24gqSU9x7BK6
jrTX6wk/s62Y7DYkb6tON3z8pWil/weaHd1ipdPmLa+UNwfCv/rrS/Don/UGe8
/mXLurdufT1FipbWAXNOgof01LRhYl/su4Z8vHUEWLOg9d9gq59cql7N+AEqIl
"
},
...
]
Define Model and API interface
@JsonIgnoreProperties(ignoreUnknown = true)
public class Key {
public int id;
@JsonProperty(“key”)
public String publicKey;
public static class List extends ArrayList<Key>{}
}
public interface GithubAPI {
@GET("/users/{user}/keys")
Response userKeys(@Path("user") String user);
}
Subclass RetrofitSpiceService
public class GithubService extends RetrofitSpiceService {
@Override
public void onCreate(){
super.onCreate();
addRetrofitInterface(GithubAPI.class);
}
@Override
public CacheManager createCacheManager(Application application) throws
CacheCreationException {
return new CacheManager().addPersister(new
JacksonRetrofitObjectPersisterFactory(application, null));
}
@Override
protected String getServerUrl() { return “https://api.github.com”; }
@Override
protected Converter createConverter() { return new JacksonConverter(); }
}
AndroidManifest and SpiceManager
<service
android:name="com.example.github.GithubService"
android:exported="false"
/>
public class GithubSpiceManager extends SpiceManager {
public GithubSpiceManager() {
super(GithubService.class);
}
}
Define Request class
public class GithubUserKeyRequest extends RetrofitSpiceRequest<Key.List.class,
GithubAPI.class> {
private final JsonReader jsonReader = new JsonReader();
private final ObjectMapper objectMapper = new ObjectMapper();
private final String user;
public GithubUserKeyRequest(String user) {
super(Key.List.class, GithubAPI.class);
this.user = user;
}
@Override
public Episode.List loadDataFromNetwork() throws Exception {
Response response = getService().userKeys(user);
Object result =
this.jsonReader.parse(response.getBody().in()).read("$.");
response.getBody().in().close();
return (Key.List)this.objectMapper.convertValue(result, Key.List.class);
}
}
Spice up your life!
public class UserKeyFragment extends Fragment {
private final GithubSpiceManager spiceManager = new GithubSpiceManager();
@Override
public void onStart() {
super.onStart();
spiceManager.start(getActivity());
spiceManager.execute(new GithubUserKeyRequest("snookle"), "cacheKey",
1000 * 60, new RequestListener<Key.List>() {
@Override
public void onRequestFailure(SpiceException e) {
Toast.makeText(getActivity(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
@Override
public void onRequestSuccess(Key.List keys) {
// do cool stuff here????
}
});
}
}
Gotchas
▪ Request converter and Cache converter are separate and defined in
different classes
▪ JSON weirdness: “null”/null, and true/false/0/1
▪ spiceManager.isDataInCache() will cause a deadlock if called from
Activity/Fragment onStart().
▪ Inner classes must be declared static to access without an instance of
outer class.
› BAD: public class List extends ArrayList<Key>{}
› NOT VERY HELPFUL EXCEPTION: JsonMappingException: No
suitable constructor found for type [simple type, class
com.example.github.Key.List]: can not instantiate from
JSON object (need to add/enable type information?)
› BETTER: public static class List extends
ArrayList<Key>{}
The lazy programmers guide to consuming web services
Ad

More Related Content

What's hot (20)

Groovy in the Cloud
Groovy in the CloudGroovy in the Cloud
Groovy in the Cloud
Daniel Woods
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
Alexis Moussine-Pouchkine
 
Lifthub (#rpscala 26)
Lifthub (#rpscala 26)Lifthub (#rpscala 26)
Lifthub (#rpscala 26)
k4200
 
Lifthub (rpscala #31)
Lifthub (rpscala #31)Lifthub (rpscala #31)
Lifthub (rpscala #31)
k4200
 
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Matt Raible
 
Intro to meteor @py gotham Aug 15-16 2015
Intro to meteor @py gotham Aug 15-16 2015Intro to meteor @py gotham Aug 15-16 2015
Intro to meteor @py gotham Aug 15-16 2015
christieewen
 
Dropwizard
DropwizardDropwizard
Dropwizard
Abdulhadi ÇELENLİOĞLU
 
Web Space10 Overview
Web Space10 OverviewWeb Space10 Overview
Web Space10 Overview
Alexis Moussine-Pouchkine
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
Fwdays
 
Micronaut For Single Page Apps
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page Apps
Zachary Klein
 
Java 9 and Beyond
Java 9 and BeyondJava 9 and Beyond
Java 9 and Beyond
Mayank Patel
 
Spring IO '15 - Developing microservices, Spring Boot or Grails?
Spring IO '15 - Developing microservices, Spring Boot or Grails?Spring IO '15 - Developing microservices, Spring Boot or Grails?
Spring IO '15 - Developing microservices, Spring Boot or Grails?
Fátima Casaú Pérez
 
Full Stack Reactive with React and Spring WebFlux - PWX 2019
Full Stack Reactive with React and Spring WebFlux - PWX 2019Full Stack Reactive with React and Spring WebFlux - PWX 2019
Full Stack Reactive with React and Spring WebFlux - PWX 2019
Matt Raible
 
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Matt Raible
 
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Matt Raible
 
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magecom UK Limited
 
Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013
Matt Raible
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
William Marques
 
Micronaut Launchpad
Micronaut LaunchpadMicronaut Launchpad
Micronaut Launchpad
Zachary Klein
 
GWT and PWA
GWT and PWAGWT and PWA
GWT and PWA
Manuel Carrasco Moñino
 
Groovy in the Cloud
Groovy in the CloudGroovy in the Cloud
Groovy in the Cloud
Daniel Woods
 
Lifthub (#rpscala 26)
Lifthub (#rpscala 26)Lifthub (#rpscala 26)
Lifthub (#rpscala 26)
k4200
 
Lifthub (rpscala #31)
Lifthub (rpscala #31)Lifthub (rpscala #31)
Lifthub (rpscala #31)
k4200
 
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Matt Raible
 
Intro to meteor @py gotham Aug 15-16 2015
Intro to meteor @py gotham Aug 15-16 2015Intro to meteor @py gotham Aug 15-16 2015
Intro to meteor @py gotham Aug 15-16 2015
christieewen
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
Fwdays
 
Micronaut For Single Page Apps
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page Apps
Zachary Klein
 
Spring IO '15 - Developing microservices, Spring Boot or Grails?
Spring IO '15 - Developing microservices, Spring Boot or Grails?Spring IO '15 - Developing microservices, Spring Boot or Grails?
Spring IO '15 - Developing microservices, Spring Boot or Grails?
Fátima Casaú Pérez
 
Full Stack Reactive with React and Spring WebFlux - PWX 2019
Full Stack Reactive with React and Spring WebFlux - PWX 2019Full Stack Reactive with React and Spring WebFlux - PWX 2019
Full Stack Reactive with React and Spring WebFlux - PWX 2019
Matt Raible
 
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Matt Raible
 
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Matt Raible
 
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magecom UK Limited
 
Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013
Matt Raible
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
William Marques
 

Similar to The lazy programmers guide to consuming web services (20)

using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
Emily Jiang
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
Emily Jiang
 
Angular beans
Angular beansAngular beans
Angular beans
Bessem Hmidi
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
Emily Jiang
 
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
Matt Raible
 
Android development
Android developmentAndroid development
Android development
Gregoire BARRET
 
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Matt Raible
 
Hybrid App using WordPress
Hybrid App using WordPressHybrid App using WordPress
Hybrid App using WordPress
Haim Michael
 
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Matt Raible
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
Alexis Hassler
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
Matt Raible
 
What's new in android jakarta gdg (2015-08-26)
What's new in android   jakarta gdg (2015-08-26)What's new in android   jakarta gdg (2015-08-26)
What's new in android jakarta gdg (2015-08-26)
Google
 
Docker & ECS: Secure Nearline Execution
Docker & ECS: Secure Nearline ExecutionDocker & ECS: Secure Nearline Execution
Docker & ECS: Secure Nearline Execution
Brennan Saeta
 
Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
Ernesto Hernández Rodríguez
 
C#on linux
C#on linuxC#on linux
C#on linux
AvarinTalks
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
Roberto Franchini
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Payara
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
Emily Jiang
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
Emily Jiang
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
Emily Jiang
 
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
Matt Raible
 
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Matt Raible
 
Hybrid App using WordPress
Hybrid App using WordPressHybrid App using WordPress
Hybrid App using WordPress
Haim Michael
 
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Matt Raible
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
Alexis Hassler
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
Matt Raible
 
What's new in android jakarta gdg (2015-08-26)
What's new in android   jakarta gdg (2015-08-26)What's new in android   jakarta gdg (2015-08-26)
What's new in android jakarta gdg (2015-08-26)
Google
 
Docker & ECS: Secure Nearline Execution
Docker & ECS: Secure Nearline ExecutionDocker & ECS: Secure Nearline Execution
Docker & ECS: Secure Nearline Execution
Brennan Saeta
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
Roberto Franchini
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Payara
 
Ad

Recently uploaded (20)

Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Ad

The lazy programmers guide to consuming web services

  • 1. The Lazy Programmers Guide to Consuming Web Services (in Android) Max Bhuiyan http://au.linkedin.com/in/mamnun Ben Kenny http://au.linkedin.com/pub/ben-kenny/3a/b9a/b67
  • 2. Disclaimer These slides are available under the Creative Commons Attribution-ShareAlike (BY-SA) 3.0 License. Trademarks and brands are the property of their respective owners. This presentation is not affiliated with Yahoo, Yahoo7 or Seven Media.
  • 3. Web API integration challenges ● Authentication ● Response deserialization ● Caching ● Unreliable Network
  • 4. Android specific challenges ● Network calls on background thread o Async Tasks o Loader o Service/Daemon ● Response Processing : CPU + Memory constraint
  • 5. No network, No problem
  • 6. Standing on the shoulders of giants ● RoboSpice ● Jackson ● JSONPath ● Retrofit ● OkHttp ● Signpost
  • 7. : Cache Manager ● Uses an AndroidService to execute network requests in background ● Plugin Architecture ● Supports request queue & prioritization ● Per request caching policy ● Handles activity/fragment lifecycle
  • 8. Jackson : JSON Processor ● FAST!!! ● Streaming parser ● Easy annotation based mapping ● Handles polymorphic types(more about this from Ben)
  • 9. RetrofitRetrofit ● Super simple API definition o 2 lines to define an endpoint o 1 class with 3 functions to code the Request ● Uses OkHttp(uses nio)
  • 12. He who controls the spice, controls the universe! -- Baron Harkonnen
  • 13. Quick example - Github Keys API $ curl -i https://api.github.com/users/snookle/keys [ { "id": 8050932, "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6lev8ySCrH9IIysnPsgpNyVcPomAM/n Gn2nC8Cx4y5ttL5K9C5He1qkw7QQW5jTDsgtdYhS5u46CvKQFzrFLcdffkEJP1 dsnR1y+PWgzpXA81xvGFrOlYBtGh3n9Iuh7z5pw2WEBXnTqLkAmDtozFkJ0uJb 0bUnIc2mVRj9noCk5/dGKnzIweKpxaMpSWhR7I46lrAWlKE1sX24gqSU9x7BK6 jrTX6wk/s62Y7DYkb6tON3z8pWil/weaHd1ipdPmLa+UNwfCv/rrS/Don/UGe8 /mXLurdufT1FipbWAXNOgof01LRhYl/su4Z8vHUEWLOg9d9gq59cql7N+AEqIl " }, ... ]
  • 14. Define Model and API interface @JsonIgnoreProperties(ignoreUnknown = true) public class Key { public int id; @JsonProperty(“key”) public String publicKey; public static class List extends ArrayList<Key>{} } public interface GithubAPI { @GET("/users/{user}/keys") Response userKeys(@Path("user") String user); }
  • 15. Subclass RetrofitSpiceService public class GithubService extends RetrofitSpiceService { @Override public void onCreate(){ super.onCreate(); addRetrofitInterface(GithubAPI.class); } @Override public CacheManager createCacheManager(Application application) throws CacheCreationException { return new CacheManager().addPersister(new JacksonRetrofitObjectPersisterFactory(application, null)); } @Override protected String getServerUrl() { return “https://api.github.com”; } @Override protected Converter createConverter() { return new JacksonConverter(); } }
  • 16. AndroidManifest and SpiceManager <service android:name="com.example.github.GithubService" android:exported="false" /> public class GithubSpiceManager extends SpiceManager { public GithubSpiceManager() { super(GithubService.class); } }
  • 17. Define Request class public class GithubUserKeyRequest extends RetrofitSpiceRequest<Key.List.class, GithubAPI.class> { private final JsonReader jsonReader = new JsonReader(); private final ObjectMapper objectMapper = new ObjectMapper(); private final String user; public GithubUserKeyRequest(String user) { super(Key.List.class, GithubAPI.class); this.user = user; } @Override public Episode.List loadDataFromNetwork() throws Exception { Response response = getService().userKeys(user); Object result = this.jsonReader.parse(response.getBody().in()).read("$."); response.getBody().in().close(); return (Key.List)this.objectMapper.convertValue(result, Key.List.class); } }
  • 18. Spice up your life! public class UserKeyFragment extends Fragment { private final GithubSpiceManager spiceManager = new GithubSpiceManager(); @Override public void onStart() { super.onStart(); spiceManager.start(getActivity()); spiceManager.execute(new GithubUserKeyRequest("snookle"), "cacheKey", 1000 * 60, new RequestListener<Key.List>() { @Override public void onRequestFailure(SpiceException e) { Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); } @Override public void onRequestSuccess(Key.List keys) { // do cool stuff here???? } }); } }
  • 19. Gotchas ▪ Request converter and Cache converter are separate and defined in different classes ▪ JSON weirdness: “null”/null, and true/false/0/1 ▪ spiceManager.isDataInCache() will cause a deadlock if called from Activity/Fragment onStart(). ▪ Inner classes must be declared static to access without an instance of outer class. › BAD: public class List extends ArrayList<Key>{} › NOT VERY HELPFUL EXCEPTION: JsonMappingException: No suitable constructor found for type [simple type, class com.example.github.Key.List]: can not instantiate from JSON object (need to add/enable type information?) › BETTER: public static class List extends ArrayList<Key>{}