Академический Документы
Профессиональный Документы
Культура Документы
For Windows and Mac please download the setup file and install.
For Linux (Download the setup file and follow the instructions to install XAMPP):
1. Retrofit Instance :
• You can create an instance of Retrofit by Retrofit.Builder class. You have to specify
the base url and converter factory at the time of the retrofit instance creation.
Retrofit
2. Model Class
• Retrofit need a POJO class for Sending and Receiving request.
• Retrofit use the POJO class for parse the server Response by using Converter like
Gson , Jackson , Moshi etc.
Retrofit
3. An interface for possible API Call
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
Manifest.xml
Allow your app to access internet
Retrofit make the network request and wait for the response on a background thread and deliver the result to
onResponse() or onFailure() methods on main UI thread.
For Testing use this link
http://dummy.restapiexample.com/
Dummy Data in JSON format
Dashboard Activity
1. Display All Employee
(@GET)
Show All Employee XML
Model class
Create an Interface
Main Activity
Output
2. Search Employee by ID (@GET)
Search Employee XML
Interface
@Path : Named replacement
in the URL path.
Search by Id result
empId value
SearchEmployeActivity
We are expecting a single Employee object ,
that is why we are not using List<Employee>
3. Register Employee (@Post)
Create another class named
EmployeeCUD
For Create , Update and Delete
For retrieving date use
Employee class.
use EmployeeCUD class.
Registration Activity
Just to remind . Use EmployeeCUD for insert ,
update and delete.
4. Update and Delete (@PUT and @Delete)
XML
Load Employee
https://github.com/kiranrana8973/HeroesAPI_WebAPi.git
Use :
1. MongoDB
2. Node.js
Add a Hero for postman
Add another hero : Postman
Post Using Retrofit2
build.gradle : Add dependency for
Retrofit and GSON
Manifest File
Create three packages
For Interface
1. Using Class
2. Using @Field
3. Using @FieldMap
1. Using Class
model class
For now properties name should be same as the
JSON values
NOTE :
Please be aware of the fact, that you can’t use this annotation for GET requests
Interface
Activity
3. Using @FieldMap
Interface
Use HashMap
1
Another way
2
Browsing image and previewing
click
here
to
browse
Activity
browse only image
Field Name