- 
- 1.1. What is Web Service?
- 1.2. Advantages of Web Service
- 1.3. Web service Architecture
- 1.4. Web Service Features
- 1.5. How Web Service works?
- 1.6. Types of Web Services
- 1.7. Components of Web Services
 
- 
Introduction to REST Web Services - 3.1. What is REST API?
- 3.2. What are RESTful Web Services?
- 3.3. Principles of REST API
- 3.4. Features of REST API
- 3.5. Method s of REST API
- 3.6. Advantages of REST API
 
Web Service is a standardized way or medium for communication between client and server applications to exchange data on the World Wide Web
Web Services provides a standard protocol/format and helps to communicate between two different application and make sure all things happening smooth-proper and successful
Web Services provide a common platform that allows multiple applications built on various programming languages to communicate and have the ability to communicate with each other
- Scenario: Java programming language can interact with PHP/ASP and .Net, JavaScript by using Web Services
Example:
Hotel/Restaurant
- The waiter is a mediator (Act as a Web Service/Bridge) between two application ie. customer and kitchen
Flight Booking websites
- All airlines companies (Air India, Indigo, Jet Airways) have exposed their Web Service through an API,
- All agents and different flight booking websites like makemytrip.com, cleartrip.com, etc. access an API and populate data/status accordingly
Here are some of the benefits and advantages of using Web Services:
- Platform independent communication: Web Service provides platform/Operating System independent communication
- Applications can Exchange Data: Through Web Services, different applications/implementations can talk to each other and exchange data/information
- Exposing Business Functionality/existing functions on the network so other applications can use the functionality of your program
- Interoperabilityamongst applications (Web services allow various applications to talk/share data and services among themselves)
- Web Services use standardized industry protocolfor the communication which everybody understands
- Reduction in costof communication/Low-Cost Communication
The Web Services architecture consists of three distinct roles as given below:
- Service Provider: The provider creates/implements the Web Service and makes it available on the internet to other client application who want to use it
- Service Requestor: Requestor is a consumer/client application that utilizes an existing web service by sending an XML request. The client application can be a .Net, Java, JavaScript or other language application which looks some sort of functionality via a web service
- Service Registry/Broker: The registry is a logically centralized directory of services where developers can publish new services or find existing ones ( like centralized clearinghouse or brokerage house for companies and their services). The broker is an application provides access to the- UDDI (Universal Description, Discovery, and Integration)which enables the client application to locate the web service
Web Services must have the following special behavioral features/characteristics:
- XML-Based: Web Services uses XML to represent the data
- Loosely Coupled: Client/Consumer and the web service are not fixed/bound/tied to each other directly
- Ability to Synchronous or Asynchronous functionality: Synchronicity specifies the binding of the client to the execution of the function, Asynchronous clients fetch their result at a later point in time, while synchronous clients receive their effect when the service has completed
- Supports Remote Procedure Calls(RPCs): Web services allow consumers to invoke procedures, functions, and methods on remote objects using an XML-based protocol. Remote systems expose input and output framework that a web service must support
- Supports Document Exchange: One of the essential benefits of XML is its generic way of representing not only data but also complex documents, it can be as simple as representing a current address, or they can be as complex as representing an entire book or Request for Quotation (RFQ)
- Coarse-Grained: Object-oriented technologies such as Java expose their functions through individual methods or coarse-grained services that approach the right amount of business logic
                  Client                          Server
                  sends REQUEST ->                <- gives RESPONSE
                  (Consume Services)              (Provide various services to use) 
                                [ ueses Medium - HTTP/INTERNET                 
                                Format - XML/JSON ]
- The client program bundle information into a SOAP message which is sent to web service as the body of an HTTP POST request
- The web service unpacks the SOAP request and converts to a command that application can understand and gives a response with required data/information
- The web service packages response into another SOAP message and sends back to the client program
- The client program unpacks the SOAP message and starts with the necessary process
There are mainly/major two ways of implementing Web Services, popular Web Services Protocols are:
- SOAP Web Services:- (Simple Object Access Protocol): [ Medium: HTTP (post), Format: XML ]
- REST Web Services:- (REpresentational State Transfer): [ Medium: HTTP (get, post, put, delete), Format: XML/JSON/Text ]
While using/consuming web services, Service Consumer (client) needs to know:
- What the Web Service is?
- What are the different services available?
- What are the various components of Web Service?
- What's the structure and description of Web Service?
- What are the different/various functionalities/return types/parameters with Web Service?
- What are the request and response parameters?
- How to call, use and consume the Web Service?
All the standard Web Services work using the following components:
- 
SOAP (Simple Object Access Protocol):- SOAP is a W3C recommendation for communication between applications and format for sending messages
- SOAP is an XML-based protocol for accessing web services and for exchanging information between computers/applications
- SOAP is simple and extensible also a platform, language-independent
 
- 
WSDL (Web Services Description Language):- WSDL is an XML-based language for describing web services and how to access them
- It's an XML based interface for the Web Services which describe all the attributes and functionalities, method name/parameter of the Web Service published by all Service Providers
- WSDL is the standard format for describing a web service which UDDI uses
 
- 
UDDI (Universal Description, Discovery, and Integration):- UDDI is an XML-based standard for describing, publishing, finding/discovering and integrating web services
- A Web Service Provider publishes his Web Service through WSDL on an online directory/registry from where consumers can query and search the Web Services
- UDDI is a platform-independent and open framework can communicate via SOAP, CORBA, and Java RMI Protocol
 
- SOAP (Simple Object Access Protocol), a W3C recommendation for communication between two applications
- SOAP is an XML-based protocol for accessing web services over HTTP
- Any Web Service that complies and follows some guidelines which are led down by SOAP Web Services specifications is a SOAP Web Service
There are two categories of SOAP Web Services specifications: as Basic specification and Extended specification:
- Basic
- SOAP
- Protocol / Rules / Definitions related to how two different applications will talk to each other over the web
- All SOAP message/information exchange happens with the common format: XML
- XML messages have a pre-defined structure as SOAP MESSAGE which consists of Envelope, Header, and Body
- Envelope - root element of a message
- Header - components, complex types, authentication parameters
- Body - actual request to be sent to the server
 
 
- XML messages have a pre-defined structure as SOAP MESSAGE which consists of Envelope, Header, and Body
 
- WSDL (Web Services Description Language)
- UDDI (Universal Description, Discovery, and Integration)
 
- SOAP
- Extended
- Web Services Security (WS-Security)
- Web Services Policy (WS-Policy)
 
W3C (World Wide Web Consortium) - [An International community that develops open standards for worldwide web] defines and dictates all standards for Web Services
- Slow: SOAP uses XML format, whose parsing is slow and consumes more bandwidth and resource
- WSDL dependent: SOAP uses WSDL and doesn't have other mechanisms to discover the service
- REST (REpresentational State Transfer)
- REST is an architectural style
- REST is not a protocol,
- there are no strict specifications,
- no central body like W3C to control specifications
 
- REST is a design principle, one can use design principles/methods to create a service, which creates RESTful Web Services
REST is an architectural style as well as an approach for communications purpose that is often used in various web services development
- Introduced by Roy Fielding in the year 2000
- It is often regarded as the "language of the internet"
- It is a stateless client and server model
- REST is used to build Web Services that are lightweight, maintainable, and scalable
Any Web Service that complies and follows some guidelines which are led down by REST architecture/principles is a called a RESTful Web Service [A service which is built on the REST architecture is called a RESTful service]
There are many principles/constraints of REST architecture a Web Service needs to follow to become/deemed as REST API / RESTful API-Web Service:
- Uniform Interface:
- Resource - Everything is a resource
- any platform, any Database, any language - we can create a module or resource for Students, Employees or anything
 
- URI - Any resource/data can be accessed by a URI
- URI = Uniform Resource Identifier
- http://domain.name/resource
- http://website.com/students
- https://website.com/employee/id=100
 
- HTTP - Make explicit use of HTTP methods
- HTTP = HyperText Transfer Protocol
- HTTP methods are: GET, POST, PUT, DELETE
- Using HTTP methods along with URI, we can REQUEST and can access/modify any resource or resource information
 
 
- Resource - Everything is a resource
- Client-Server:
- Client & Server are separate identities, Clients send REQUEST and Server RESPONDS with headers, status or response body
 
- Stateless:
- All client-server communications are stateless
- In case of REST, the server does not maintain any state of the system and client has to send the request which is complete/proper in itself (every request will be independent and will not be dependent on any previous requests)
- Each request from the client to the server - must contain all the data that is necessary to handle the request, no need to store any data on the server
- A server should not require to store the state of a session
- As the server does not store any old/past/unwanted data, it improves Web Service performance
 
- Cacheable:
- Caching happens at the client-side
- The client uses the Cache-Control header to determine whether to cache the resource (make a local copy) or not
- The server generates responses that indicate whether they are cacheable or not to improve the performance by reducing number of requests for duplicate resources [server does it with the help of Cache-Control and Last-Modified (date value)]
 
- Layered System:
- Multiple Layers can exist between client and server
- Layers can include Proxies, Gateways, Caching they are HTTP intermediaries
- Layers can be used for message translations / improving performance with caching etc.
- Enables security, load-balancing and share caching to improve application performance
- Proxies - Proxy server evaluates, control its complexity and simplify the request
- Gateways - Used to manage traffic on the network, protocol translations, etc.
- Caching - Improves performance and scalability
 
- Code On Demand:
- Ability to download and execute code on the client-side
 
- Simpler than SOAP API
- Proper Documentation available
- Throws/Log proper Error messages
- Creat = POST method - Read = GET method - Update = PUT method - Delete = DELETE method
- POST– Create a new data/info/record using the RESTful web service
- GET- Get a list of all data/info/record
- PUT- Update all data/info/record
- DELETE- Delete all data/info/record
- Fast: Due to no strict specification like SOAP, REST consumes less bandwidth and resource
- Language and Platform independent: Can be written in any programming language and executed in any platform
- Permits different data format: Plain Text, HTML, XML and JSON
- Can use SOAP: RESTful web services can use SOAP API/web services as the implementation
There are many differences between SOAP and REST web services, some important differences are given below:
| SOAP Web Services/API | REST Web Services/API | 
|---|---|
| SOAP stands for Simple Object Access Protocol | REST stands for REpresentational State Transfer | 
| SOAP is a protocol | REST is an architectural style | 
| SOAP can't use REST because it is a protocol but REST is an architectural pattern | REST can use SOAP web services as it is an architectural pattern/concept and can use any protocol like HTTP, SOAP | 
| SOAP uses service interfacesto expose the business logic | REST uses URI (URL path)to expose business logic | 
| SOAP requires more bandwidth and resourcethan REST | REST requires less bandwidth and resourcethan SOAP | 
| SOAP is slowas compared to REST | REST is fastas compared to SOAP | 
| SOAP permits XMLdata format only | REST permits different data format such as Plain text, HTML, JSON, XMLetc. | 
| SOAP is less preferredthan REST | REST IS more preferredthan SOAP |