Webservices Demystified
By: Tannishk Sharma
Tags: Scalability, Web Development, Microservices, Computer Science, Rest Api

According to W3C Web service is

A web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL ). Other systems interact with the web service in a manner prescribed by its description using SOAP -messages, typically conveyed using HTTP with an XML serialization in conjunction with other web-related standards.

This definition may have made some sense in the SOAP era, but we are in REST era, so let’s define different properties of web services.

A web service is a software system designed to support interoperable machine-to-machine interaction over a network. What does this mean? In simple term web services written in any language be it java node or python flask should have a way to communicate with one another Web Service should have a service definition which defines different URIs and request and response structure. We can use WSDL or Swagger(We used to use this in Urbanclap ) for the same We can use any transport protocol using HTTP or RPC within services We can use any data exchange format like JSON or XML.

Web Services

Lets us first discuss what everyone hates but Goldman Sachs loves .

SOAP

Soap stands for simple object access protocol. For a wide variety of time, SOAP is used in service-oriented architecture. It became the preferred protocol to achieve interoperability between applications.

Remember that SOAP is a protocol. SOAP is designed with a specification. It includes a WSDL file which has the required information about the web service does in addition to the location of the resources on the web service ie their URI .

SOAP API makes use of XML with a predefined structure for data exchange. A typical SOAP XML structure looks like the following

Typical SOAP Structure

Different parts of SOAP structure

SOAP Envelope: Identifies the XML document as a SOAP message. SOAP Header: Contains header information. SOAP Body: Contains call and response information.

REST

Rest stands for Representation State Transfer . REST is an Architectural style in which a web service can only be treated as a RESTful service if it follows the constraints

Client-Server : It is based on the client-server architecture Statelessness: State of the request is not saved at the server. We require all the information from the request to process it successfully. If two clients send the same request, they get a similar response. REST services permit different data exchange format such as Plain text, HTML, XML, JSON, etc. But the most preferred format for exchanging data is JSON. REST uses URI to locate a particular resource Layered System: A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way. If a proxy or load balancer is placed between the client and server, it won’t affect their communications, and there won’t be a need to update the client or server code. Intermediary servers can improve system scalability by enabling load balancing and by providing shared caches. Also, security can be added as a layer on top of the web services, and then clearly separate business logic from security logic. Adding security as a separate layer enforces security policies. Finally, it also means that a server can call multiple other servers to generate a response to the client. (Src: Wikipedia ) Caches: RESTful clients and intermediaries can cache responses.

Web Service APIs which adhere to the REST architectural constraints are called RESTful APIs. Typical REST Apis make use of HTTP protocol and have the following properties :

1. URI (Uniform Resource Locator): URL on which resource at the web service can be accessed. E.g. GET /users/

2. HTTP Methods: Different Types of HTTP methods are as follows:

Different HTTP Methods

3 . Request and response data format which can anything ranging from JSON, XML to HTML. We prefer to use JSON as our data exchange format.

In Summary :