Using Retrofit framework in implementation of Android REST client David Ante Macan*, Zlatko Stapić, Milan Pavlović* University of Zagreb Faculty of Organization.

Slides:



Advertisements
Similar presentations
Pierre-Johan CHARTRE Java EE - JAX-RS - Pierre-Johan CHARTRE
Advertisements

Give it a REST already Arnon Rotem-Gal-Oz VP R&D xsights
REST Vs. SOAP.
REST Introduction 吴海生 博克软件(杭州)有限公司.
Building and using REST information services Rion Dooley.
Introduction to Web Services
Server Access The REST of the Story David Cleary
RESTful Web Services Senthil Chinnaiyan, Senior Architect
Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
Building RESTful Interfaces
Peoplesoft: Building and Consuming Web Services
Controling instrument in the RESTful way
CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.
Web Services Michael Smith Alex Feldman. What is a Web Service? A Web service is a message-oriented software system designed to support inter-operable.
Integrating Complementary Tools with PopMedNet TM 27 July 2015 Rich Schaaf
Introduction SOAP History Technical Architecture SOAP in Industry Summary References.
Designing and Implementing Web Data Services in Perl
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
REST vs SOAP for Web Services Applications and Services in Internet Benjamin Hilaire – 81747L
Google Data APIs Google Data APIs : Integrando suas aplicações Java com os serviços Google.
Microsoft Visual Studio 2010 Muhammad Zubair MS (FAST-NU) Experience: 5+ Years Contact:- Cell#:
Prepared By : Monika Darji Web Services using REST & JAX-WS.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
WEB API: WHY THEY MATTER ECOL 453/ Nirav Merchant
Web Services XML-RPC, SOAP, REST Advanced Web-based Systems | Misbhauddin.
Python and REST Kevin Hibma. What is REST? Why REST? REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a.
Microsoft Visual Studio 2010 Muhammad Zubair MS (FAST-NU) Experience: 5+ Years Contact:- Cell#:
Copyright © Cybage Software Pvt. Ltd. All Rights Reserved. Cybage Confidential. Drupal Web Services 1 Authored by: Chaitanya Anil Kulkarni Presented.
RESTful Web Service 2014 년 12 월 한연희
1 Seminar on Service Oriented Architecture Principles of REST.
World Wide Web “WWW”, "Web" or "W3". World Wide Web “WWW”, "Web" or "W3"
Web Architecture update for WSAWG/WSDL TAG published Principles of the Web Contents: –Identifiers Most of the work –Formats Not much –Protocols Summary.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
1 Alternative view on Internet Computing Web 1.0 –Web 1.0 is first generation, Web Information based. Driven by Information provider. Web 2.0 Ajax enabled.
Advanced Web Technologies Lecture #4 By: Faraz Ahmed.
Web Technologies Lecture 1 The Internet and HTTP.
RESTful Web Services What is RESTful?
GEO PLACES EXPLORER PRESENTED BY KHUSHBOO BAGHADIYA SUMANA VENKATESH.
Web Services An Introduction Copyright © Curt Hill.
REST By: Vishwanath Vineet.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Feeling RESTful? Well, first we’ll define a Web Service –A web page meant to be consumed by a computer via an autonomous program as opposed to a web browser.
© 2010 IBM Corporation RESTFul Service Modelling in Rational Software Architect April, 2011.
Representational State Transfer COMP6017 Topics on Web Services Dr Nicholas Gibbins –
Programming for RESTful-SOA An introduction to building a SOA System with light-weighted RESTful Web Services (Web Services without SOAP or WSDL) Xiong.
REST REPRESENTATIONAL STATE TRANSFER Scott Ainsworth & Louis Nguyen (Group 1) Old Dominion University, CS 791: Web Syndication Formats, January 29, 2008.
REST API Design. Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently.
Embt.co/sprint-rest-json-services Blog Notes: Building RESTful servers. In C++ Builder Developer Skill Sprint Tips, Tricks and Techniques The Ultimate.
Introduction to Web Services
The Client-Server Model
WEB SERVICES.
REST: Web Services Abel Sanchez.
REST- Representational State Transfer Enn Õunapuu
Node.js Express Web Services
Unit – 5 JAVA Web Services
Advanced Web-based Systems | Misbhauddin
Ashish Pandit IT Architect, Middleware & Integration Services
WEB API.
$, $$, $$$ API testing Edition
Web services introduction, application and its future
A gentle introduction to RESTful APIs
REST APIs Maxwell Furman Department of MIS Fox School of Business
RESTful Web Services.
REST på Microsoft-stacken
Introduction to Web Services and SOA
Week 05 Node.js Week 05
A gentle introduction to RESTful APIs
Distributed System using Web Services
WCF Data Services and Silverlight
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Using Retrofit framework in implementation of Android REST client David Ante Macan*, Zlatko Stapić, Milan Pavlović* University of Zagreb Faculty of Organization and Informatics Pavlinska 2, Varaždin, Croatia CASE27 – Developers conference – Zagreb, Croatia * Students at University of Zagreb, FOI Varazdin

Agenda Introduction REST Architecture Android client implementation Implementation using Retrofit Conclusion References Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Introduction Today’s mobile applications are Internet dependent > 90% [1], [3] Web services are used for supporting mobile application functionalities  Internet dependent monetization models  App usage statistics, data synchronization, social components, score tables… Backend servers for push notifications Web service – self contained and self describing application component that can be used by other applications and can be communicated by using open protocols [6] Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Introduction After SOA became widely used for mobile and other applications, the dominant way of exchanging the data with web services was by using SOAP [7] XML used for creating requests and responses was too complex and requests had to be build manually -> problematic due to protocols intolerance on any errors REST (Representational State Transfer) provides lightweight alternative and relies on simple URL approach REST can output the data in any format (for example in CSV, JSON or RSS). Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

REST Architecture  Architectural style for distributed hypermedia systems, as Roy Fielding originally described it in his doctoral dissertation in 2000 [8]  Contains 6 main characteristics: 1.Uniform interface  Resource based  Manipulation of resources through representations  Usage of self-descriptive messages  Hypermedia as the engine of application state 2.Statelessness 3.Caching 4.Client-server separation 5.Layering 6.Code on demand Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

REST Architecture  HTTP request semantics Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June Request MethodDescription GET Used for retrieving (or read) a representation of a resource. If everything works, HTTP GET response contains a representation in XML or JSON with response code of 200 (OK). POST Most often used for creation of new resources. It is actually used to create subordinate or child resource of some other (parent) resource. When server receives POST request, it creates new resource and assigns it a new ID. PUT Used for update operations. Request body should contain newly-updated representation of the original resource which is identified by a known resource URI. DELETE Used to delete URI-identified resource.

Android client implementation Example system  Address Manager - enables users to get geographical location (latitude and longitude) of any user defined address Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Android client implementation Web service specification   x-www-form-urlencoded request Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June URLMethodParamsResponse example baseGET- [{"id":1,"location":"Ivanec","lat": " ","lon":" "}, …] basePOSTlocation {"id":1,"location":"Ivanec","lat": " ","lon":" "} base/idPUTlocation{"id":1,"location":"Ivanec 2", "lat": " ","lon":" "}

Android client implementation Native Android web-service consumption  web service communication layer  response parsing layer  manual threading Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Android client implementation Native Android web-service consumption  Repository – consists of set of methods that are leaning on web services  Service – represents web-service communication layer. This class should be flexible to be able to execute any web service request.  Callback – interface to be implemented by any callback object containing logic for receiving web-service response.  Parser – static class containing knowledge on parsing the responses. Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Android client implementation Native Repository Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Android client implementation Retrofit implementation  type-safe REST client for Android and Java  turns your REST API into a Java interface  upon downloading the data is parsed into POJO which must be defined for each "resource" in the response  flexible in message format  uses compile-time annotation processor Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Android client implementation Retrofit implementation  Define API interface  Define RetrofitHelper that will instantiate adapter and interface Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Android client implementation Retrofit implementation  Call methods  Handle response Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

Conclusion We presented  REST application architectural style  Two implementations of web-service communication layer Main contribution  Architectural design for the two approaches Native vs Retrofit approach  Native approach is robust and hard to adapt  Retrofit is straightforward and flexible Source code  Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June

References [1] D. Bosomworth, “Mobile marketing statistics 2015” Smart Insights, Available at: [Accessed: May-2015] [2] ComScore Inc., “The U.S. Mobile App Report” Available at: [3] Statista, “Statistics and facts on Mobile Internet Usage,” Statista.com, [Online]. Available at: [Accessed: May-2015]. [4] Android Developers, “Google Cloud Messaging for Android | Android Developers” Google Services, [Online]. Available at: [Accessed: May-2015]. [5] Apple inc., “Local and Push Notifications for Developers - Apple Developer” Developer Apple.com, [Online]. Available at: [Accessed: May-2015]. [6] W3Schools.com, “Introduction to Web Services” Introduction to Web Services, [Online]. Available at: [Accessed: May-2015]. [7] W3Schools.com, “SOAP Introduction”, [Online]. Available at: webservices/ws_soap_intro.asp [Accessed: May-2015]. [8] R. T. Fielding, “Architectural Styles and the Design of Network-based Software Architectures” UNIVERSITY OF CALIFORNIA, Irvine, [9] A. Nene, “Web Services Architecture – When to Use SOAP vs REST” Javalobby, [Online]. Available at: [Accessed: May-2015]. [10] J. Mueller, “Understanding SOAP and REST Basics” Software Quality Matters Blog, [Online]. Available at: [Accessed: May-2015]. [11] F. Todd, “RESTful Service Best Practices, Recommendations for Creating Web Services” RestAPITutorial.com, [12] CodePath.com, “Consuming APIs with Retrofit” CodePath Android Cliffnotes, [Online]. Available at: [Accessed: May-2015]. [13] StudyTrials, “Java Google Json (Gson) Introduction” StudyTrials.com. [Online]. Available at: [Accessed: May-2015]. [14] “Google Gson” Google Gson Home, [Online]. Available at: site/gson/Home [Accessed: May-2015] Macan, Stapić, Pavlović: Using Retrofit framework in implementation of Android REST client - CASE27, 2 nd June