Types of Web ServicesThere are two types of web services:
RESTful Web ServicesREST stands for REpresentational State Transfer. It is developed by Roy Thomas Fielding who also developed HTTP. The main goal of RESTful web services is to make web services more effective. RESTful web services try to define services using the different concepts that are already present in HTTP. REST is an architectural approach, not a protocol. It does not define the standard message exchange format. We can build REST services with both XML and JSON. JSON is more popular format with REST. The key abstraction is a resource in REST. A resource can be anything. It can be accessed through a Uniform Resource Identifier (URI). For example: The resource has representations like XML, HTML, and JSON. The current state is captured by representational resource. When we request a resource, we provide the representation of the resource. The important methods of HTTP are:
For example, if we want to perform the following actions in the social media application, we get the corresponding results. POST /users: It creates a user. GET /users/{id}: It retrieve the detail of one user. GET /users: It retrieve the detail of all users. DELETE /users: It delete all users. DELETE /users/{id}: It delete a user. GET /users/{id}/posts/post_id: It retrieve the detail of a specific post. POST / users/{id}/ posts: It creates a post for a user. GET /users/{id}/post: Retrieve all posts for a user HTTP also defines the following standard status code:
RESTful Service Constraints
Advantages of RESTful web services
SOAP Web ServicesREST defines an architectural approach whereas SOAP poses a restriction on the format of the XML. XML transfer data between the service provider and service consumer. Remember that SOAP and REST are not comparable. SOAP: SOAP acronym for Simple Object Access Protocol. It defines the standard XML format. It also defines the way of building web services. We use Web Service Definition Language (WSDL) to define the format of request XML and the response XML. For example, we have requested to access the Todo application from the Facebook application. The Facebook application sends an XML request to the Todo application. Todo application processes the request and generates the XML response and sends back to the Facebook application. If we are using SOAP web services, we have to use the structure of SOAP. In the above figure, the SOAP-Envelope contains a SOAP-Header and SOAP-Body. It contains meta-information needed to identify the request, for example, authentication, authorization, signature, etc. SOAP-Header is optional. The SOAP-Body contains the real XML content of request or response. In case of an error, the response server responds back with SOAP-Fault. Let's understand the SOAP XML request and response structure. XML Request XML Response Points to remember
The Endpoint is the connection point where HTML or ASP pages are exposed. It provides the information needed to address the Web Service endpoint. The operations are the services that are allowed to access. Request structure defines the structure of the request, and the response structure defines the structure of the response.
Next TopicWeb Services Components
|