SlideShare a Scribd company logo
PREPARING YOUR WEB
SERVICES FOR ANDROID AND
 THE OTHER WAY AROUND
            SPEAKER:
       AURAS DUMANOVSCHI
OVERVIEW
● Web services: play nice with others

● Response formats

● Optimization

● Tips

● Android: using the web data

● Increasing the speed of your app
WEB SERVICES



?
WHY
WEB SERVICES



?{
      ● Offloads the data gathering,
        transformation and storage to a
        powerful server.

      ● Can do a lot of things in a very
        short time

      ● It’s connected to a large internet
WHY     pipe
IS THERE A   2ND   CHOICE?
IS THERE A   2ND   CHOICE?

        Yes!
IS THERE A        2ND     CHOICE?

             Yes!
    Where else can you get data from?
IS THERE A        2ND     CHOICE?

             Yes!
    Where else can you get data from?


    Web pages
IS THERE A        2ND     CHOICE?

              Yes!
    Where else can you get data from?


     Web pages
   That means parsing HTML client side.
YEAH, SO?



           {
               ● It takes a lot of bandwidth to download



BIG
a few            some web pages

               ● Mobile devices are usually connected to
                 high latency networks: cell towers. Not
                 even wi-fi is as reliable as fiber optic.
PROBLEMS
               ● You may have to do this a lot of times
                 just for all the data needed for a single
                 screen
OK…

You can do all that on a web server in less than the
time* for a request from a 3G Galaxy Nexus to
reach the web server.



*that’s if you don’t have the data stored in a DB and
you have to fetch it from one or more sources.
SO, WEB SERVICES…

● Just like Q & A
SO, WEB SERVICES…

● Just like Q & A
                    {   Q: THE REQUEST
SO, WEB SERVICES…

● Just like Q & A
                    {   Q: THE REQUEST

                        A: THE RESPONSE
SO, WEB SERVICES…

● Just like Q & A
                    {   Q: THE REQUEST

                        A: THE RESPONSE


● Types: REST & SOAP;
SOAP
● REQUEST: XML, specific format;

● RESPONSE: XML, specific format;
REST

● REQUEST: HTTP or other*;

● RESPONSE: XML or JSON; any type of
  document you like;



  *HTTP is the norm. But you can also
  have XML or JSON requests.
XML VS JSON

● XML: human readable and compatible
  with most platforms;

● JSON: compact and quick to parse;
NO DATA ON YOUR SERVER?

 ● Scrape it;

 ● Cache it and/or store it;

 ● Serve the data later from the local cache;
SIMPLE PLAN OF A PARSER
   ● Start point;

   ● Data gathering points;

   ● End point ;

   ● Regular expressions;
START, DATA, END
FEROVIAR
STRUCTURING DATA
● Try and return only one type of object per
  API call

● For every object type use the same
  schema everywhere.

● In some cases you can return less data
  per object, but where you have more data
  return it in the same format
STRUCTURING DATA
● If your objects have many-to-many
  relationships with other objects remove
  redundancies

I.e : use person_id to identify a person and
at the end of the response return all the
unique persons in the current call
STRUCTURING DATA


   Use pagination!
BUT IF YOU CAN’T…

● Add an API call that tells you if the data
  has been changed (timestamp, hash,
  integer, etc)

● At least make sure you compress the
  response
ANDROID SUPPORTS GZIP,
          DEFLATE
// REQUEST
HttpUriRequest request = new HttpGet(url);
request.addHeader("Accept-Encoding", "gzip");
// ...
httpClient.execute(request);

// RESPONSE
InputStream instream = response.getEntity().getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null &&
contentEncoding.getValue().equalsIgnoreCase("gzip")) {
    instream = new GZIPInputStream(instream);
}
TIPS

● Build an API call that returns images in the request
  shape & size;

● Less bandwidth required, less memory used and
  less CPU time spent on rendering (no more
  stretching/shrinking, positioning and cropping);
TIPS

● Never trust the client;

● Do your security and policy checks server side
  also;

● Secure every call with a signature: call
  parameters, private key, timestamp or unique
  call id per session ➔ hashed;
ANDROID SIDE OF THINGS

 ● Parsing JSON: JSONObject or Jackson

 ● Objects vs Streaming
ANDROID SIDE OF THINGS

 ● Generate objects from the data only if you need
   them right then;

 ● In some cases (loading screens) you may need
   to load a lot of data for later use;

 ● Throw lots of data straight to a SQLite DB using
   TRANSACTIONS
WHY TRANSACTIONS?

● Not just a concept borrowed from traditional
  *SQL databases

● Uses less I/O. A whole lot less I/O.

● Like 100x faster than saving each data line by
  line
REDESCOPERA ROMANIA
SAVING
● To SQLite Databases: persistent objects with later
  use

● To static objects: volatile objects that will only be
  used just this session

● To parcelable objects: even more volatile objects

● To SharedPreferences: persistent key-value data or
  singleton objects
CACHING

● Always cache to the filesystem the images you
  download from the web;

● That’s what the ~/cache dir is for;

● Limit your bitmap memory cache and make sure
  you also recycle the bitmaps when you clear them
  from the cache;
PLAYING NICE WITH THE WEB
         SERVICE
 Detect unique install id: generate a GUID


 SharedPreferences prefs =
 context.getDefaultSharedPreferences();
 String uniqueGUID = prefs.getString("install_guid",
 null);

 if (uniqueGUID == null) {
 ! uniqueGUID = UUID.randomUUID().toString()
 ! prefs.edit().putString("install_guid",
 uniqueGUID).commit();
 }
PLAYING NICE WITH THE WEB
         SERVICE
 Detect unique device id: use ANDROID_ID


 String deviceId =
 Settings.Secure.getString(contentResolver,Settings.Se
 cure.ANDROID_ID);
PLAYING NICE WITH THE WEB
         SERVICE
● Send debugging and app identification data in HTTP
  header

● App Name/Version

● Device manufacturer/Model/ID


  Helps debugging issues remotely and

  Allows web admins to control access to their web service
THANKS

email: auras@wip.ro

twitter: @auras

This presentation is available at:

http://wip.ro/droidcon/auras.pdf

More Related Content

What's hot (20)

PDF
Getting started with node JS
Hamdi Hmidi
 
PPTX
Introduction about-ajax-framework
Sakthi Bro
 
PDF
AtlasCamp 2014: Static Connect Add-ons
Atlassian
 
PDF
AtlasCamp 2014: Writing Connect Add-ons for Confluence
Atlassian
 
PDF
MongoDB and Node.js
Norberto Leite
 
PDF
Log File Analysis: The most powerful tool in your SEO toolkit
Tom Bennet
 
PPTX
Getting Started with Web Services
DataNext Solutions
 
ODP
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Masoud Kalali
 
PPTX
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Fastly
 
PDF
Engage 2013 - Multi Channel Data Collection
Webtrends
 
PDF
Ng init | EPI Sousse
Hamdi Hmidi
 
ODP
Real time web (Orbited) at BCNE3
Alex Kavanagh
 
PDF
Building Next Generation Real-Time Web Applications using Websockets
Naresh Chintalcheru
 
PPT
Scalable Reliable Secure REST
guestb2ed5f
 
KEY
Web Optimization Level: Paranoid
robin_sy
 
PDF
Introduction to performance tuning perl web applications
Perrin Harkins
 
PDF
MongoDB and the MEAN Stack
MongoDB
 
PDF
Building Scalable Websites with Perl
Perrin Harkins
 
PPT
Bigger Stronger Faster
Chris Love
 
PDF
Inside election night at The New York Times | Altitude NYC
Fastly
 
Getting started with node JS
Hamdi Hmidi
 
Introduction about-ajax-framework
Sakthi Bro
 
AtlasCamp 2014: Static Connect Add-ons
Atlassian
 
AtlasCamp 2014: Writing Connect Add-ons for Confluence
Atlassian
 
MongoDB and Node.js
Norberto Leite
 
Log File Analysis: The most powerful tool in your SEO toolkit
Tom Bennet
 
Getting Started with Web Services
DataNext Solutions
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Masoud Kalali
 
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Fastly
 
Engage 2013 - Multi Channel Data Collection
Webtrends
 
Ng init | EPI Sousse
Hamdi Hmidi
 
Real time web (Orbited) at BCNE3
Alex Kavanagh
 
Building Next Generation Real-Time Web Applications using Websockets
Naresh Chintalcheru
 
Scalable Reliable Secure REST
guestb2ed5f
 
Web Optimization Level: Paranoid
robin_sy
 
Introduction to performance tuning perl web applications
Perrin Harkins
 
MongoDB and the MEAN Stack
MongoDB
 
Building Scalable Websites with Perl
Perrin Harkins
 
Bigger Stronger Faster
Chris Love
 
Inside election night at The New York Times | Altitude NYC
Fastly
 

Viewers also liked (20)

PDF
خدمات الويب (Web Services) و كيف تنشئها
lunarhalo
 
PPSX
5 android web_service
Saber LAJILI
 
PDF
مقدمة عن بايثون / جانقو
lunarhalo
 
PDF
بناء تطبيقات ويب 2.0. دروس مستفادة و نصائح موجهة
lunarhalo
 
PPTX
Openerp 8
smiste
 
PDF
[Android] Web services
Nikmesoft Ltd
 
PPTX
Odoo Module de Fabrication
Analystik
 
PPTX
Webservice for android ppt
santosh lamba
 
PDF
OpenERP/Odoo: Fiche Technique
Africa Performances
 
PDF
Atelier1 mise en place d’odoo
Abdelouahed Abdou
 
PDF
Migration gmao de openerp 6.1 vers odoo 8
HORIYASOFT
 
PDF
Atelier2 Odoo: Gestion des Ressources Humaines (installation, employés, contr...
Abdelouahed Abdou
 
PDF
Développement de modules pour odoo (anciennement OpenERP): exemples et exerci...
Abdelouahed Abdou
 
PPTX
Python et son intégration avec Odoo
Hassan WAHSISS
 
PPT
Android ppt
Ansh Singh
 
PDF
Formation Android (Initiation à la programmation sous Android)
G²FOSS ENIT
 
PDF
Paramétrage et développement spécifique des modules odoo(OpenERP) Partie 1
Addi Ait-Mlouk
 
PDF
Odoo gestion des stocks v8
Africa Performances
 
PDF
Odoo: Tableaux de bord et Reporting
Africa Performances
 
PDF
Gestion Comptable et Financiere Odoo V8
Africa Performances
 
خدمات الويب (Web Services) و كيف تنشئها
lunarhalo
 
5 android web_service
Saber LAJILI
 
مقدمة عن بايثون / جانقو
lunarhalo
 
بناء تطبيقات ويب 2.0. دروس مستفادة و نصائح موجهة
lunarhalo
 
Openerp 8
smiste
 
[Android] Web services
Nikmesoft Ltd
 
Odoo Module de Fabrication
Analystik
 
Webservice for android ppt
santosh lamba
 
OpenERP/Odoo: Fiche Technique
Africa Performances
 
Atelier1 mise en place d’odoo
Abdelouahed Abdou
 
Migration gmao de openerp 6.1 vers odoo 8
HORIYASOFT
 
Atelier2 Odoo: Gestion des Ressources Humaines (installation, employés, contr...
Abdelouahed Abdou
 
Développement de modules pour odoo (anciennement OpenERP): exemples et exerci...
Abdelouahed Abdou
 
Python et son intégration avec Odoo
Hassan WAHSISS
 
Android ppt
Ansh Singh
 
Formation Android (Initiation à la programmation sous Android)
G²FOSS ENIT
 
Paramétrage et développement spécifique des modules odoo(OpenERP) Partie 1
Addi Ait-Mlouk
 
Odoo gestion des stocks v8
Africa Performances
 
Odoo: Tableaux de bord et Reporting
Africa Performances
 
Gestion Comptable et Financiere Odoo V8
Africa Performances
 
Ad

Similar to Preparing your web services for Android and your Android app for web services @Droidcon Bucharest 2012 (20)

PDF
20 tips for website performance
Andrew Siemer
 
ODP
Deploying Perl apps on dotCloud
daoswald
 
PDF
Design Web Service API by HungerStation
ArabNet ME
 
PPTX
Delivering High Performance Websites with NGINX
NGINX, Inc.
 
PPTX
Introduction to amazon web services for developers
Ciklum Ukraine
 
PDF
Netflix oss season 1 episode 3
Ruslan Meshenberg
 
PDF
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
MongoDB
 
PDF
Serverless Big Data Architecture on Google Cloud Platform at Credit OK
Kriangkrai Chaonithi
 
PDF
Future of Serverless
Yoav Avrahami
 
PDF
Ten practical ways to improve front-end performance
Andrew Rota
 
PDF
Write less (code) and build more with serverless
Dhaval Nagar
 
PDF
Combining ReST and Context for Killer iPhone Apps
jasonc411
 
PPTX
Advanced Web Technology.pptx
ssuser35fdf2
 
PDF
Engage 2022: The Superpower of Integrating External APIs for Notes and Domino...
Serdar Basegmez
 
PDF
kranonit S06E01 Игорь Цинько: High load
Krivoy Rog IT Community
 
PPTX
What's New in NGINX Plus R10?
NGINX, Inc.
 
PPTX
iPhone Development For Experienced Web Developers
lisab517
 
PPTX
App Deployment on Cloud
Ajey Pratap Singh
 
PDF
Decoupled (Headless) Drupal
Daniel Stout
 
PDF
IoT-javascript-2019-fosdem
Phil www.rzr.online.fr
 
20 tips for website performance
Andrew Siemer
 
Deploying Perl apps on dotCloud
daoswald
 
Design Web Service API by HungerStation
ArabNet ME
 
Delivering High Performance Websites with NGINX
NGINX, Inc.
 
Introduction to amazon web services for developers
Ciklum Ukraine
 
Netflix oss season 1 episode 3
Ruslan Meshenberg
 
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
MongoDB
 
Serverless Big Data Architecture on Google Cloud Platform at Credit OK
Kriangkrai Chaonithi
 
Future of Serverless
Yoav Avrahami
 
Ten practical ways to improve front-end performance
Andrew Rota
 
Write less (code) and build more with serverless
Dhaval Nagar
 
Combining ReST and Context for Killer iPhone Apps
jasonc411
 
Advanced Web Technology.pptx
ssuser35fdf2
 
Engage 2022: The Superpower of Integrating External APIs for Notes and Domino...
Serdar Basegmez
 
kranonit S06E01 Игорь Цинько: High load
Krivoy Rog IT Community
 
What's New in NGINX Plus R10?
NGINX, Inc.
 
iPhone Development For Experienced Web Developers
lisab517
 
App Deployment on Cloud
Ajey Pratap Singh
 
Decoupled (Headless) Drupal
Daniel Stout
 
IoT-javascript-2019-fosdem
Phil www.rzr.online.fr
 
Ad

Preparing your web services for Android and your Android app for web services @Droidcon Bucharest 2012

  • 1. PREPARING YOUR WEB SERVICES FOR ANDROID AND THE OTHER WAY AROUND SPEAKER: AURAS DUMANOVSCHI
  • 2. OVERVIEW ● Web services: play nice with others ● Response formats ● Optimization ● Tips ● Android: using the web data ● Increasing the speed of your app
  • 4. WEB SERVICES ?{ ● Offloads the data gathering, transformation and storage to a powerful server. ● Can do a lot of things in a very short time ● It’s connected to a large internet WHY pipe
  • 5. IS THERE A 2ND CHOICE?
  • 6. IS THERE A 2ND CHOICE? Yes!
  • 7. IS THERE A 2ND CHOICE? Yes! Where else can you get data from?
  • 8. IS THERE A 2ND CHOICE? Yes! Where else can you get data from? Web pages
  • 9. IS THERE A 2ND CHOICE? Yes! Where else can you get data from? Web pages That means parsing HTML client side.
  • 10. YEAH, SO? { ● It takes a lot of bandwidth to download BIG a few some web pages ● Mobile devices are usually connected to high latency networks: cell towers. Not even wi-fi is as reliable as fiber optic. PROBLEMS ● You may have to do this a lot of times just for all the data needed for a single screen
  • 11. OK… You can do all that on a web server in less than the time* for a request from a 3G Galaxy Nexus to reach the web server. *that’s if you don’t have the data stored in a DB and you have to fetch it from one or more sources.
  • 12. SO, WEB SERVICES… ● Just like Q & A
  • 13. SO, WEB SERVICES… ● Just like Q & A { Q: THE REQUEST
  • 14. SO, WEB SERVICES… ● Just like Q & A { Q: THE REQUEST A: THE RESPONSE
  • 15. SO, WEB SERVICES… ● Just like Q & A { Q: THE REQUEST A: THE RESPONSE ● Types: REST & SOAP;
  • 16. SOAP ● REQUEST: XML, specific format; ● RESPONSE: XML, specific format;
  • 17. REST ● REQUEST: HTTP or other*; ● RESPONSE: XML or JSON; any type of document you like; *HTTP is the norm. But you can also have XML or JSON requests.
  • 18. XML VS JSON ● XML: human readable and compatible with most platforms; ● JSON: compact and quick to parse;
  • 19. NO DATA ON YOUR SERVER? ● Scrape it; ● Cache it and/or store it; ● Serve the data later from the local cache;
  • 20. SIMPLE PLAN OF A PARSER ● Start point; ● Data gathering points; ● End point ; ● Regular expressions;
  • 23. STRUCTURING DATA ● Try and return only one type of object per API call ● For every object type use the same schema everywhere. ● In some cases you can return less data per object, but where you have more data return it in the same format
  • 24. STRUCTURING DATA ● If your objects have many-to-many relationships with other objects remove redundancies I.e : use person_id to identify a person and at the end of the response return all the unique persons in the current call
  • 25. STRUCTURING DATA Use pagination!
  • 26. BUT IF YOU CAN’T… ● Add an API call that tells you if the data has been changed (timestamp, hash, integer, etc) ● At least make sure you compress the response
  • 27. ANDROID SUPPORTS GZIP, DEFLATE // REQUEST HttpUriRequest request = new HttpGet(url); request.addHeader("Accept-Encoding", "gzip"); // ... httpClient.execute(request); // RESPONSE InputStream instream = response.getEntity().getContent(); Header contentEncoding = response.getFirstHeader("Content-Encoding"); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); }
  • 28. TIPS ● Build an API call that returns images in the request shape & size; ● Less bandwidth required, less memory used and less CPU time spent on rendering (no more stretching/shrinking, positioning and cropping);
  • 29. TIPS ● Never trust the client; ● Do your security and policy checks server side also; ● Secure every call with a signature: call parameters, private key, timestamp or unique call id per session ➔ hashed;
  • 30. ANDROID SIDE OF THINGS ● Parsing JSON: JSONObject or Jackson ● Objects vs Streaming
  • 31. ANDROID SIDE OF THINGS ● Generate objects from the data only if you need them right then; ● In some cases (loading screens) you may need to load a lot of data for later use; ● Throw lots of data straight to a SQLite DB using TRANSACTIONS
  • 32. WHY TRANSACTIONS? ● Not just a concept borrowed from traditional *SQL databases ● Uses less I/O. A whole lot less I/O. ● Like 100x faster than saving each data line by line
  • 34. SAVING ● To SQLite Databases: persistent objects with later use ● To static objects: volatile objects that will only be used just this session ● To parcelable objects: even more volatile objects ● To SharedPreferences: persistent key-value data or singleton objects
  • 35. CACHING ● Always cache to the filesystem the images you download from the web; ● That’s what the ~/cache dir is for; ● Limit your bitmap memory cache and make sure you also recycle the bitmaps when you clear them from the cache;
  • 36. PLAYING NICE WITH THE WEB SERVICE Detect unique install id: generate a GUID SharedPreferences prefs = context.getDefaultSharedPreferences(); String uniqueGUID = prefs.getString("install_guid", null); if (uniqueGUID == null) { ! uniqueGUID = UUID.randomUUID().toString() ! prefs.edit().putString("install_guid", uniqueGUID).commit(); }
  • 37. PLAYING NICE WITH THE WEB SERVICE Detect unique device id: use ANDROID_ID String deviceId = Settings.Secure.getString(contentResolver,Settings.Se cure.ANDROID_ID);
  • 38. PLAYING NICE WITH THE WEB SERVICE ● Send debugging and app identification data in HTTP header ● App Name/Version ● Device manufacturer/Model/ID Helps debugging issues remotely and Allows web admins to control access to their web service
  • 39. THANKS email: [email protected] twitter: @auras This presentation is available at: http://wip.ro/droidcon/auras.pdf