SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Retrofit
* Released by Square.
* Retrofit turns your REST API into a Java interface.
* Offers very easy to use REST API Solution.
Retrofit Performance Analysis
Retrofit uses these library
lOkHttp
lGSON
lRxJava
GSON
lConversion of an object to json or from json to object.
lAll the fields by default are included in conversions even
private fields
lIf don’t want to include the field in conversion, use
transient modifier for that field
GSON Implementation
* This is a class for Person-
public class Person {
public String id;
@SerializedName(user_name)
public String name;
public Person parent;
//setter getter here
}
Obtains result like this
GSON Implementation
GSON Serialization
class PersonSerializer implements
JsonSerializer<Person> {
public JsonElement serialize(final Person person, Type
type,JsonSerializationContext context) {
JsonObject result = new JsonObject();
result.add("id", new JsonPrimitive(person.getId()));
result.add("name", new
JsonPrimitive(person.getName()));
Person parent = person.getParent();
if (parent != null) {
RxJava
Reactive Programming
Reactive Programming
Reactive Programming
Retrofit
1-Create Interface for API and declare methods for each
REST Call
2-Specify method type Using Annotations-
@GET,@POST,@PUT
3-For paramenters use -
@Path,@Query,@Body
4-Use RestAdapter to build the service client.
Retrofit Interface
public interface TestService {
@GET("/users/{user}/person")
List<Person> listPerson(@Path("user") String user);
}
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.test.com")
.build();
TestService service =
restAdapter.create(TestService.class);
Interface's Methods
lA method with a return type will be executed
synchronously.
lAsynchronous execution requires the last parameter of the
method be a Callback.
l Using RxJava we can have return type as Observable
Interface's Methods
lPublic interface TestInterface{
@GET("/users/list")
Photo userList(); //Synchronous call
@POST("/users/list")
void userList(@Body User ,Callback<TResponse> cb);
//Asynchronous call
@GET("/users/list")
Observable<TResponse> userList();//Observable
HEADER MANIPULATION
lSet static headers for a method using
l@Headers("Cache-Control: max-age=640000")
lUse when need to send same header for all api-
lRequestInterceptor requestInterceptor = new
RequestInterceptor() {
l @Override
l public void intercept(RequestFacade request) {
l request.addHeader("User-Agent", "Retrofit-Sample-
App");
Retrofit Implementation
* Retrofit uses Gson by default to convert HTTP bodies to
and from JSON.
* Custom GSON Converter Example
If you want to specify behavior that is different from
Gson's defaults.
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapter(MyType2.class, new
MyTypeAdapter());
Retrofit Implementation
* Create gson object this way-
Gson gson = new
GsonBuilder().registerTypeAdapter(Person.class, new
PersonSerializer())
.create();
* Pass this object to .setConverter
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.github.com")
.setConverter(new GsonConverter(gson))
RestAdapter
*Using RestAdapter Object we initialize Interface
reference or service client.
* It has static class RestAdapter.Builder.
methods inside RestAdapter.Builder class-
*setEndpoint-API endpoint URL
*setClient-The HTTP client used for requests
*setRequestInterceptor-for adding Header/data to every
request.
setConverter-converter used for serialization and
Retrofit Implementation
* RestAdapter.Builder()
.setEndpoint(“http://www.githubservice.com”)
.setClient(new OkClient(okHttpClientWithCache()))
.setConverter(new GsonConverter(new
GsonBuilder().registerTypeAdapter(Test.class, new
TestDeserializer())
.build()
.create(TestInterface.class);
Retrofit Implementation
* Use http://www.jsonschema2pojo.org/ to create POJO
classes. Lets take this example-
{
"weather":[
{
"id":711,
"main":"Smoke",
"description":"smoke",
"icon":"50n"
Retrofit Implementation
Implementaion
* It Shows how to use SimpleXMLConverter to
communicate with an API that uses XML
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.soundcloud.com")
.setConverter(new SimpleXMLConverter())
.build();
TestInterrface service =
restAdapter.create(TestInterface.class);
THANK YOU
l
Contact Cumulations
Are you looking for a mobile apps development team who can understand your business
requirement & develop a user-centric apps?
Email: sales@cumulations.com
Visit us at: http://www.cumulations.com/
Let’s Talk

Weitere ähnliche Inhalte

Was ist angesagt?

Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Intro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich AndroidIntro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich AndroidEgor Andreevich
 
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018Loiane Groner
 
Deep Dumpster Diving
Deep Dumpster DivingDeep Dumpster Diving
Deep Dumpster DivingRonnBlack
 
FullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + AngularFullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + AngularLoiane Groner
 
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConfFull-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConfLoiane Groner
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Loiane Groner
 
Reactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJavaReactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJavaMatt Stine
 
OASGraph LoopBack 4 Integration
OASGraph LoopBack 4 IntegrationOASGraph LoopBack 4 Integration
OASGraph LoopBack 4 IntegrationMario Estrada
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]Igor Lozynskyi
 
Spring data ii
Spring data iiSpring data ii
Spring data ii명철 강
 

Was ist angesagt? (20)

Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
 
Intro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich AndroidIntro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich Android
 
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
Retro vs volley (2)
Retro vs volley (2)Retro vs volley (2)
Retro vs volley (2)
 
Deep Dumpster Diving
Deep Dumpster DivingDeep Dumpster Diving
Deep Dumpster Diving
 
Introduction to Reactive Java
Introduction to Reactive JavaIntroduction to Reactive Java
Introduction to Reactive Java
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 
FullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + AngularFullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + Angular
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConfFull-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
 
Reactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJavaReactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJava
 
OASGraph LoopBack 4 Integration
OASGraph LoopBack 4 IntegrationOASGraph LoopBack 4 Integration
OASGraph LoopBack 4 Integration
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]
 
Spring data ii
Spring data iiSpring data ii
Spring data ii
 

Andere mochten auch

introduce Okhttp
introduce Okhttpintroduce Okhttp
introduce Okhttp朋 王
 
Simplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o RetrofitSimplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o RetrofitFelipe Pedroso
 
大鱼架构演进
大鱼架构演进大鱼架构演进
大鱼架构演进Jun Liu
 
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 Andres Almiray
 
Seismic retrofit methods
Seismic retrofit methodsSeismic retrofit methods
Seismic retrofit methodsPaul McMullin
 
Staying Afloat with Buoy: A High-Performance HTTP Client
Staying Afloat with Buoy: A High-Performance HTTP ClientStaying Afloat with Buoy: A High-Performance HTTP Client
Staying Afloat with Buoy: A High-Performance HTTP Clientlpgauth
 

Andere mochten auch (6)

introduce Okhttp
introduce Okhttpintroduce Okhttp
introduce Okhttp
 
Simplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o RetrofitSimplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o Retrofit
 
大鱼架构演进
大鱼架构演进大鱼架构演进
大鱼架构演进
 
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
 
Seismic retrofit methods
Seismic retrofit methodsSeismic retrofit methods
Seismic retrofit methods
 
Staying Afloat with Buoy: A High-Performance HTTP Client
Staying Afloat with Buoy: A High-Performance HTTP ClientStaying Afloat with Buoy: A High-Performance HTTP Client
Staying Afloat with Buoy: A High-Performance HTTP Client
 

Ähnlich wie Retrofit Technology Overview by Cumulations Technologies

The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeVMware Tanzu
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Mule esb object_to_jackson_json
Mule esb object_to_jackson_jsonMule esb object_to_jackson_json
Mule esb object_to_jackson_jsonDavide Rapacciuolo
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScripttaobao.com
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Mule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converterMule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converterRaffaela Vitiello
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashBret Little
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDr. Jan Köhnlein
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in CassandraJairam Chandar
 
Modern Networking with Swish
Modern Networking with SwishModern Networking with Swish
Modern Networking with Swishjakecraige
 

Ähnlich wie Retrofit Technology Overview by Cumulations Technologies (20)

Why realm?
Why realm?Why realm?
Why realm?
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache Geode
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Ejb3 Dan Hinojosa
Ejb3 Dan HinojosaEjb3 Dan Hinojosa
Ejb3 Dan Hinojosa
 
Mule esb object_to_jackson_json
Mule esb object_to_jackson_jsonMule esb object_to_jackson_json
Mule esb object_to_jackson_json
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Mule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converterMule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converter
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
 
Spring data
Spring dataSpring data
Spring data
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit Xtext
 
Overloading
OverloadingOverloading
Overloading
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in Cassandra
 
Lecture5
Lecture5Lecture5
Lecture5
 
Modern Networking with Swish
Modern Networking with SwishModern Networking with Swish
Modern Networking with Swish
 

Mehr von Cumulations Technologies

Dependency Injection in Android with Dagger 2
Dependency Injection in Android with Dagger 2Dependency Injection in Android with Dagger 2
Dependency Injection in Android with Dagger 2Cumulations Technologies
 
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud MessagingPush Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud MessagingCumulations Technologies
 
Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects Cumulations Technologies
 
On Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech TalksOn Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech TalksCumulations Technologies
 
Modes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech TalksModes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech TalksCumulations Technologies
 
IoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech TalksIoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech TalksCumulations Technologies
 

Mehr von Cumulations Technologies (10)

Dependency Injection in Android with Dagger 2
Dependency Injection in Android with Dagger 2Dependency Injection in Android with Dagger 2
Dependency Injection in Android with Dagger 2
 
It’s All About Design
It’s All About DesignIt’s All About Design
It’s All About Design
 
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud MessagingPush Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
 
Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects
 
Understanding of MQTT for IoT Projects
Understanding of MQTT for IoT ProjectsUnderstanding of MQTT for IoT Projects
Understanding of MQTT for IoT Projects
 
Android App with Meatwear
Android App with MeatwearAndroid App with Meatwear
Android App with Meatwear
 
On Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech TalksOn Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech Talks
 
Modes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech TalksModes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech Talks
 
IoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech TalksIoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech Talks
 
IoT(internet of Things) Basics
IoT(internet of Things)  BasicsIoT(internet of Things)  Basics
IoT(internet of Things) Basics
 

Kürzlich hochgeladen

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
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 REVIEWERMadyBayot
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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 challengesrafiqahmad00786416
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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 Takeoffsammart93
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Kürzlich hochgeladen (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Retrofit Technology Overview by Cumulations Technologies

  • 1. Retrofit * Released by Square. * Retrofit turns your REST API into a Java interface. * Offers very easy to use REST API Solution.
  • 3. Retrofit uses these library lOkHttp lGSON lRxJava
  • 4. GSON lConversion of an object to json or from json to object. lAll the fields by default are included in conversions even private fields lIf don’t want to include the field in conversion, use transient modifier for that field
  • 5. GSON Implementation * This is a class for Person- public class Person { public String id; @SerializedName(user_name) public String name; public Person parent; //setter getter here } Obtains result like this
  • 7. GSON Serialization class PersonSerializer implements JsonSerializer<Person> { public JsonElement serialize(final Person person, Type type,JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("id", new JsonPrimitive(person.getId())); result.add("name", new JsonPrimitive(person.getName())); Person parent = person.getParent(); if (parent != null) {
  • 12. Retrofit 1-Create Interface for API and declare methods for each REST Call 2-Specify method type Using Annotations- @GET,@POST,@PUT 3-For paramenters use - @Path,@Query,@Body 4-Use RestAdapter to build the service client.
  • 13. Retrofit Interface public interface TestService { @GET("/users/{user}/person") List<Person> listPerson(@Path("user") String user); } RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("https://api.test.com") .build(); TestService service = restAdapter.create(TestService.class);
  • 14. Interface's Methods lA method with a return type will be executed synchronously. lAsynchronous execution requires the last parameter of the method be a Callback. l Using RxJava we can have return type as Observable
  • 15. Interface's Methods lPublic interface TestInterface{ @GET("/users/list") Photo userList(); //Synchronous call @POST("/users/list") void userList(@Body User ,Callback<TResponse> cb); //Asynchronous call @GET("/users/list") Observable<TResponse> userList();//Observable
  • 16. HEADER MANIPULATION lSet static headers for a method using l@Headers("Cache-Control: max-age=640000") lUse when need to send same header for all api- lRequestInterceptor requestInterceptor = new RequestInterceptor() { l @Override l public void intercept(RequestFacade request) { l request.addHeader("User-Agent", "Retrofit-Sample- App");
  • 17. Retrofit Implementation * Retrofit uses Gson by default to convert HTTP bodies to and from JSON. * Custom GSON Converter Example If you want to specify behavior that is different from Gson's defaults. GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapter(MyType2.class, new MyTypeAdapter());
  • 18. Retrofit Implementation * Create gson object this way- Gson gson = new GsonBuilder().registerTypeAdapter(Person.class, new PersonSerializer()) .create(); * Pass this object to .setConverter RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("https://api.github.com") .setConverter(new GsonConverter(gson))
  • 19. RestAdapter *Using RestAdapter Object we initialize Interface reference or service client. * It has static class RestAdapter.Builder. methods inside RestAdapter.Builder class- *setEndpoint-API endpoint URL *setClient-The HTTP client used for requests *setRequestInterceptor-for adding Header/data to every request. setConverter-converter used for serialization and
  • 20. Retrofit Implementation * RestAdapter.Builder() .setEndpoint(“http://www.githubservice.com”) .setClient(new OkClient(okHttpClientWithCache())) .setConverter(new GsonConverter(new GsonBuilder().registerTypeAdapter(Test.class, new TestDeserializer()) .build() .create(TestInterface.class);
  • 21. Retrofit Implementation * Use http://www.jsonschema2pojo.org/ to create POJO classes. Lets take this example- { "weather":[ { "id":711, "main":"Smoke", "description":"smoke", "icon":"50n"
  • 23. Implementaion * It Shows how to use SimpleXMLConverter to communicate with an API that uses XML RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("https://api.soundcloud.com") .setConverter(new SimpleXMLConverter()) .build(); TestInterrface service = restAdapter.create(TestInterface.class);
  • 25. Contact Cumulations Are you looking for a mobile apps development team who can understand your business requirement & develop a user-centric apps? Email: sales@cumulations.com Visit us at: http://www.cumulations.com/ Let’s Talk