What is Web Service
lA software system designed to support
communication between machine-to-machine over
a network
lprovide standared format of communication
lPlatform independent communication
Built on PHP
OS: Apache
Built on .NET
OS: Windows
Where we use Web Service
lWeb services allows you to expose the functionality of your
existing code over the network.
lOnce it is exposed on the network, other application can
use the functionality of your program without passing actual
logic or code
lCan be consider as a class and object in refrence of OOPS
lLike Payment Gatway, google API, etc
Where we can use Web Service
SMS Service
Organization Other Bussiness
organization
API
Request
API
Response
SOAP
(Simple Object Access Protocol)
REST
(Representational state transfer)
Type Of Web
Service
Web Services
How Web Services Work
lLet assume two different platform is present
lOne built on PHP( app1) and other on .NET(app2) and is on
diffrent server
lHere we need
lmedium 'HTTP' / 'Internet' protocal
lFormat XML / JSON (comman format that both will
understand)
REST
lUse Medium “ HTTP POST PUT GET
DELETE PATCH what ever format HTTP
support”
lUSE FORMAT XML, JSON, Text what ever
format HTTP support
What is Restful web service
lA web service which is used to communicate between clinet-
server using REST Arch. / principle.
lREST is an architectural style, while SOAP is a protocol.
REST is not a standard in itself, but RESTful implementations
make use of standards, such as HTTP, URI, JSON, and XML.
Principle of REST Architecture
lUser interface
lStateless
lCacheable
lLayered System
lCode on Demand (optional)
User Interface
1) Resource:- Every thing is resource
2) URI:- Any resource data can accessed by URI
3) HTTP:- make use of HTTP method
Employee
- id
- name
Designation
- id
- name
And many
more.......
Emplyee
managment
system
Employe
e
Designatio
n
1. Resource: Every thing is resource
Employee
- id
- name
Designation
- id
- name
And many
more.......
Emplyee
managment
system
Employee
Designatio
n
1. Resource: Every thing is resource
Every module of project we can define
As Resource
Employee
- id
- name
Designation
- id
- name
And many
more.......
Emplyee
managment
system
Employe
e
Designatio
n
1. Resource: Every thing is resource
2. URI: Any Resource can be accessed
by URI (Uniform Resource Identifier)
For Example:
www.myrest.com/designation
www.myrest.com/designation/1
0
Resource
URI
What will be url if i want all employee having
given
Designation?
Employee
- id
- name
Designation
- id
- name
And many
more.......
Emplyee
managment
system
Employe
e
Designatio
n
1. Resource: Every thing is resource
2. URI: Any Resource can be accessed by URI (Uniform Resource Identifier)
For Example:
www.myrest.com/designation
www.myrest.com/designation/1
0
Resource
URI
www.myrest.com/designation/10/employe
e
Employee
- id
- name
Designation
- id
- name
And many
more.......
Emplyee
managment
system
Employe
e
Designatio
n
1. Resource: Every thing is resource
2. URI: Any Resource can be accessed by URI (Uniform Resource Identifier)
For Example:
www.myrest.com/designation
www.myrest.com/designation/1
0
Resource
URI
3. HTTP Verb
VERB
lGET
lPOST
lPUT
lDELETE
Employee
- id
- name
Designation
- id
- name
And many
more.......
Emplyee
managment
system
Employe
e
Designatio
n
1. Resource: Every thing is resource
2. URI: Any Resource can be accessed by URI (Uniform Resource Identifier)
For Example:
www.myrest.com/designation
www.myrest.com/designation/1
0
Resource
URI
3. HTTP Verb
VERB
lGET
lPOST
lPUT
lDELETE
Nam
e
Stateless
:
lServer does not maintatin any data of any previous request has been made
lNo Session
lEvery request will be independent and its client responsiblity to send all details
whatever needed fro that request
lFor example:
Client Serve
r
www.apicall.com/login + POST data (uname +
pass)
Response: { status: success, auth token: xyz
}
www.apicall.com/myPayslip + authtoken (in
header)
Cachin
g
lThis happen at client side.
Responses must therefore, implicitly or explicitly,
define themselves as cacheable or not to prevent clients from reusing
lstale or inappropriate data in response to further requests
lWell-managed caching partially or completely eliminates some client–server
interactions, further improving scalability and performance.
Layering:
A client cannot ordinarily tell whether it is connected directly to
the end server, or to an intermediary along the way.
Intermediary servers may improve system scalability by
enabling load balancing and by providing shared caches. They
may also enforce security policies.
Clinet ServerProxy Cache
REST Summary
lREST is architectural Structure
lWe must follow all principle of REST in order to improve
performace, Portablity, Visibility, Simplicity
Web Service Authentication
lFor Authentication you can use any logic which ever seems to
be secure can be used
lBasic Authentication
l- pass username and password in header
Web Service
Authentication(cont.)
lCustom Authentation
lWhen login generate token and send in response
lThis will be saved in cookies and will be used to pass
along with further transaction by setting this in header
lCan use Oauth2
lYou can create your own authentication(can change header),
it totaly depends on developer only security is concern.
Web Service
Authentication(cont.)
lCustom Authentation
lWhen login generate token and send in response
lThis will be saved in cookies and will be used to pass
along with further transaction by setting this in header
lCan use Oauth2
lYou can create your own authentication(can change header),
it totaly depends on developer only security is concern.
What is SOAP
lSOAP is also web service but use medium as a POST
lSOAP is protocol used for exchanging data between client and
server
lIT uses XML technologies as a messaging.
lXML -> eXtensible Markup Language.
lHTML -> Hyper text Markup Language
lSOAP can work on HTTP, SMTP, FTP
lSOAP is platform- and language-independent
lSOAP defines its own security known as WS Security.
The SOAP Structure
lA SOAP message contains 3 parts:
lEnvelope: defines the content of the message
lHeader (optional): contains header information
lBody: contains call and response information
From the http://schemas.xmlsoap.org/soap/envelope/
namespace
SAOP Envelope
The SOAP envelope indicates the start and the end of the
message so that the receiver knows when an entire message
has been received
The Envelope is the top element of the XML document
representing the message.
The Envelope element is always the root element of a
SOAP message.
The Envelope element contains an optional Header
element followed by a mandatory Body element.
SOAP Vs REST
SOAP REST
SOAP is a protocol REST is an architectural style.
Standards to be strictly followed. does not define too much standards
like SOAP.
SOAP requires more bandwidth and
resource than REST.
REST requires less bandwidth and
resource than SOAP.
SOAP permits XML data format only. REST permits different data format
such as Plain text, HTML, XML,
JSON etc.