4android Kotlin - Android Web Service

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Android Web Service

Communication between different system:


• Android and Web
• IOS and Web
• Web and Web (Two Web System)
• Offer Service (Partial Access, Credit Card).

BY : ENG. HAZEM A. AL REKHAWI 2


BY : ENG. HAZEM A. AL REKHAWI 3
BY : ENG. HAZEM A. AL REKHAWI 4
BY : ENG. HAZEM A. AL REKHAWI 5
BY : ENG. HAZEM A. AL REKHAWI 6
BY : ENG. HAZEM A. AL REKHAWI 7
• Application Programming Interface - API
• API and Web service serve as a means of communication.
• A Web service always needs a network for its operation whereas
an API doesn’t need a network for its operation.
• An API acts as an interface between two different applications
so that they can communicate with each other.

BY : ENG. HAZEM A. AL REKHAWI 8


• All Web services are APIs but all APIs are not Web services.
• A Web service uses only three styles of use: SOAP, REST and
XML-RPC for communication whereas API may use any style for
communication(.H files in C/C++, JAR files in Java, XML over
HTTP, JSON over HTTP, etc.)

BY : ENG. HAZEM A. AL REKHAWI 9


BY : ENG. HAZEM A. AL REKHAWI 10
BY : ENG. HAZEM A. AL REKHAWI 11
BY : ENG. HAZEM A. AL REKHAWI 12
• Representational State Transfer.
• REST expresses the architecture used in developing web
services, which aims to set standards that control systems
resource management and define how they are addressed and
transferred via HTTP to a wide range of different applications
regardless of the programming languages in which they have
been developed the Applications.
BY : ENG. HAZEM A. AL REKHAWI 13
• REST is the most dominant web design architecture in recent
years for ease of use and handling.
• Architecture style for designing networked applications.
• Relies on a Stateless, Client-Server protocol, almost always
HTTP.
• Can be used by virtually any programming language.

BY : ENG. HAZEM A. AL REKHAWI 14


A unique address for each service

BY : ENG. HAZEM A. AL REKHAWI 15


• GET: Retrieve data from a specified resource.

• POST: Submit data to be processed to a specified resource.

• PUT: Update a specified resource.

• DELETE: Delete a specified resource.

BY : ENG. HAZEM A. AL REKHAWI 16


Web Service

BY : ENG. HAZEM A. AL REKHAWI 17


Web Service

BY : ENG. HAZEM A. AL REKHAWI 18


Web Service

BY : ENG. HAZEM A. AL REKHAWI 19


Web Service

BY : ENG. HAZEM A. AL REKHAWI 20


BY : ENG. HAZEM A. AL REKHAWI 21
BY : ENG. HAZEM A. AL REKHAWI 22
BY : ENG. HAZEM A. AL REKHAWI 23
BY : ENG. HAZEM A. AL REKHAWI 24
BY : ENG. HAZEM A. AL REKHAWI 25
BY : ENG. HAZEM A. AL REKHAWI 26
CATEGORY DESCRIPTION
Communicates transfer protocol-level
1xx: Informational
information.
Indicates that the client’s request was accepted
2xx: Success
successfully.
Indicates that the client must take some
3xx: Redirection additional action in order to complete their
request.
This category of error status codes points the
4xx: Client Error
finger at clients.
The server takes responsibility for these error
5xx: Server Error
status codes.

BY : ENG. HAZEM A. AL REKHAWI 27


• 200 (OK)
It indicates that the REST API successfully carried out whatever action the
client requested.

• 201 (Created)
A REST API responds with the 201 status code whenever a resource is created
inside a collection.

BY : ENG. HAZEM A. AL REKHAWI 28


• 304 (Not Modified)
It indicates that the response body must be empty.

• 401 (Unauthorized)
A 401 error response indicates that the client tried to operate on a protected
resource without providing the proper authorization.

BY : ENG. HAZEM A. AL REKHAWI 29


• 404 (Not Found)
The 404 error status code indicates that the REST API can’t map the client’s
URI to a resource but may be available in the future.
• 405 (Method Not Allowed)
The API responds with a 405 error to indicate that the client tried to use an
HTTP method that the resource does not allow. For instance, a read-only
resource could support only GET and HEAD, while a controller resource might
allow GET and POST, but not PUT or DELETE.

BY : ENG. HAZEM A. AL REKHAWI 30


• 500 (Internal Server Error)
500 is the generic REST API error response. Most web frameworks
automatically respond with this response status code whenever they execute
some request handler code that raises an exception.
• 501 (Not Implemented)
The server either does not recognize the request method, or it lacks the ability
to fulfill the request.

BY : ENG. HAZEM A. AL REKHAWI 31


BY : ENG. HAZEM A. AL REKHAWI 32
BY : ENG. HAZEM A. AL REKHAWI 33
• Easy to use
• Small data size exchanging.
• Data exchange between different web and mobile.
• Design and development of the service regardless of the way
the data is presented.

BY : ENG. HAZEM A. AL REKHAWI 34


• Object Response URL
https://api.androidhive.info/volley/person_object.json
• Array Response URL
https://api.androidhive.info/volley/person_array.json
• Object and Array Response URL
https://api.androidhive.info/contacts/

BY : ENG. HAZEM A. AL REKHAWI 35


Download
Postman From
Here..

BY : ENG. HAZEM A. AL REKHAWI 36


BY : ENG. HAZEM A. AL REKHAWI 37
BY : ENG. HAZEM A. AL REKHAWI 38
BY : ENG. HAZEM A. AL REKHAWI 39
Example 1

Write Android code


to create this JSON data and
read it in Logcat window.

BY : ENG. HAZEM A. AL REKHAWI 40


Create JSON

BY : ENG. HAZEM A. AL REKHAWI 41


Get JSON

BY : ENG. HAZEM A. AL REKHAWI 42


hrekhawi@iugaza.edu.ps
h.alrekhawi@gmail.com

BY : ENG. HAZEM A. AL REKHAWI 43

You might also like