Web services, SOAP, and REST!👀

Irushinie Muthunayake
5 min readMay 15, 2021

What is Web service? 🧐

✮ Web service is a service that is available all over the web.

✮ It enables the communication between applications over the web. Also, it allows to exchange of the data is preferably in standard formats like JSON or XML

✮ Web services provide standard protocols for communication

Ref: https://www.fiverr.com/speed_programer/work-on-web-services-web-api-and-third-party-apis-integrations

Below are some characteristics of Web services:

⚀ Loosely coupled

⚀ Dynamic discovery

⚀ Modular

⚀ Self-contained

Advantages of Web services:

✬ One web service and be utilized by multiple applications at the same time.

✬ Easy to deploy.

✬ Web services are based on web technologies.

✬ Doesn't need large memory.

Web Service Architecture.

Three roles in web service architecture can be described below.

  1. Service Provider- This is the platform that hosts the services. (When considering From an architectural view)
  2. Service Requestor- the client application which needs to contact a web service.
  3. Service Registry- Service applicants find services and obtain binding data for services in the development period.

Two main types of Web services:

✮ SOAP-based

✮ REST-based

When choosing between SOAP and REST, it all depends on requirements of the project.

SOAP — Simple Object Access Protocol

✶ It provides access to web services.

✶ SOAP is a protocol and it has a specific structure.

✶ SOAP uses XML as its message format.

✶ Its requests have a unified look and organization.

✶SOAP is like using an envelope ( That means extra overhead, more bandwidth required, and has more work on both ends)

SOAP Message Building Blocks

SOAP Message contains the following:

The Envelope — This is the most necessary element of every message, which starts and finishes the messages with its tags, enveloping it, hence the name.
The Header — (This is optional) decides the specifics, additional needs for the message, for example, authentication.

The body element — Includes the response or request.

The Fault element — (This is also optional) displays all data about any errors that could appear throughout the API request and response

What is WSDL — Web Service Description Language?🙄

This is a document based on XML, and it supplies technical information about the web service. The method name, port types, service endpoint, binding, method parameters, etc are some of the information which is in the WSDL document.

And below figure shows the message structure of SOAP

Ref: https://flylib.com/books/en/2.439.1.22/1/

✶ SOAP needs specifications to set up the mandatory XML structure.

✶ SOAP is great for Financial Transactions.

Below is an example of a SOAP message that contains header blocks(Ref:https://www.ibm.com/docs/en/integration-bus/10.0?topic=soap-structure-message)

<?xml version='1.0' Encoding='UTF-8' ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header>
<m:reservation xmlns:m="http://travelcompany.example.org/reservation"
env:role="http://www.w3.org/2003/05/soap-envelope/role/next">
<m:reference>uuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d</m:reference>
<m:dateAndTime>2007-11-29T13:20:00.000-05:00</m:dateAndTime>
</m:reservation>
<n:passenger xmlns:n="http://mycompany.example.com/employees"
env:role="http://www.w3.org/2003/05/soap-envelope/role/next">
<n:name>Fred Bloggs</n:name>
</n:passenger>
</env:Header>
<env:Body>
<p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel">
<p:departure>
<p:departing>New York</p:departing>
<p:arriving>Los Angeles</p:arriving>
<p:departureDate>2007-12-14</p:departureDate>
<p:departureTime>late afternoon</p:departureTime>
<p:seatPreference>aisle</p:seatPreference>
</p:departure>
<p:return>
<p:departing>Los Angeles</p:departing>
<p:arriving>New York</p:arriving>
<p:departureDate>2007-12-20</p:departureDate>
<p:departureTime>mid-morning</p:departureTime>
<p:seatPreference></p:seatPreference>
</p:return>
</p:itinerary>
</env:Body>
</env:Envelope>

Let’s see some advantages and disadvantages of SOAP

Advantages:

☛ Security

☛ Standardization

☛ Extensibility

Disadvantages:

☛ More complex

☛ Worse performance

☛ Doesn’t support JSON and other formats

☛ Testing cannot be done easily in Browsers

☛ Less flexibility

☛ Resource consuming

Communication Layer of SOAP Client/Server. Ref:https://www.researchgate.net/figure/Communication-Layer-SOAP-Client-Server_fig2_253142444

SOAP Use Cases

⚀ Asynchronous Processing

⚀ Strict Agreements

⚀ Stateful Operations

REST — Representational State Transfer

Ref:https://www.javatpoint.com/soap-and-rest-web-services

✶REST is not a protocol

✶And REST is an approach to architecture.

✶REST mostly works on HTTP.

✶REST define with an interface description language.(XML, JSON, HTML ..etc)

✶Rest needs only a tiny bandwidth.

✶We can say, the REST is like a postcard. (As this lightweight, can be cached and easier to update)

✶HTTP methods supported by REST are :

GET- to get

POST-to create

PUT- to update

DELETE-to delete

✶ Rest is more suitable for running multiple operations.

Let’s see some advantages and disadvantages of REST

Advantages:

☛ High performance

☛ Flexibility

☛ Browser Friendliness

☛ Scalabilty

Disadvantages:

☛ Not suitable for distributed environments

☛ Lack of state

REST Use Cases

⚀ Limited Connection

⚀ Caching

⚀ Coding simplicity

⚀ Stateless operations

So let's see some differences between SOAP and REST

SOAP vs REST

Kafka messages

This is an open-source project that supplies messaging serviceability, root on a distributed commit log, which lets us publish and subscribe data to a course of data messages. Also, this is a TCP-based messaging protocol.

It supplies a durable, fast, and scalable procedure for exchanging data between applications.

Kafka is a very famous option for cloud-based architectures.

Below are some use cases of Kafka Messages:

✬ Web site activity tracking
✬ General messaging
✬ Logging and metrics

References

--

--