Rest and Soap

Ravindran Kugan
4 min readMay 16, 2021

In this article we will be looking at the two of the most used web API’s in the industry. I will be giving a brief introduction on what an API is and then give a look into REST and SOAP.

API

All of us are using the internet for our day to day activity. On the internet we all are using different web sites and their services to complete a specific task. Lets say for example we use a booking application to book an hotel room. For that booking app to do this task, it must communicate with various systems that works with it, for example it must communicate with google map to show available hotels, a date system to keep the bookings record and can also be using payment gateways for online transactions. This booking app is communicating with various different systems, including 3rd party systems (Google Maps). So in order for this application to communicate with other services there has to be an intermediator which will help to communicate. This is where API’s (Application Programming Interface) is used.

API:(Soruce : REDHAT)

There are various different API’s in use for web services. So in order to standardize them there are some specifications and protocols on the market. We will be looking at the two major specifications that is used today, which are SOAP and REST.

SOAP (Simple Objects Access Protocol)

The abbreviation of SOAP is Simple Objects Access Protocol. In simpler terms SOAP is a web communication protocol that transfers data on top of HTTP and SMTP (HTTP is more widely used).

As explained in the above section this protocol should be able to communicate with web services that are written in different languages. For that SOAP is written using the XML data format only. Web services that need to communicate with each other will be sending XML documents back and forth.

Note: XML means eXtensible Markup Language. It does not have predetermined tags like html. XML files are both human and machine readable. XML files cannot display to the screen like HTML documents. Click here for more information.

SOAP can be written to be,

  1. Stateful : Stateful means that the server will keep the client information after a request is completed. For example take a look at a online bank operation. If a transaction is made the server should know the amount transferred to show the new balance. In simple terms stateful is like having a conversation with a person.
  2. Stateless : Stateless is the opposite of stateful, stateless doesn’t keep track of previous requests. Once the response for a request is sent it will simply forget about the request.

SOAP is a secure protocol because it uses WS-Security specification and also works along well with SSL (Secure Socket Link).

REST (Representational State Transfer)

Rest means Representational State Transfer. What is the representational state in rest? It means to represent a data in the server to the client in a way that client can understand. REST is not a protocol it is an Architecture. REST supports several formats (XML, JSON, HTML ) to transfer data.

Because rest is an architecture developers have much more flexibility in creating a RESTful application. For an application to be classified as RESTful it must have the following capabilities;

  • client-server architecture.
  • The communication should be STATELESS.
  • Cacheable data that streamlines client-server interactions. Which means that client side will store frequently accessed data as a cache for faster response time.
  • A layered system that organizes the server.

People say that RESTful applications are asynchronous. This however is false as REST works on top of HTTP which uses synchronous communication (Click here to learn about HTTP). To make REST truly asynchronous we will be putting a man called as message broker in the middle. (An article about message broker will be coming soon 😉)

When to use which?

Now that we know what SOAP and REST are, we should also know about when to use which.

SOAP protocol is a heavy protocol (XML). It is heavy compared with REST. But security wise SOAP is much more secure compared with the latter. So applications that handles highly sensitive data and need keep track of all transactions (Stateful) should be using SOAP. For example Bank applications and high secure enterprise applications are built using SOAP.

REST is a lightweight architecture (JSON) due to the file transfer type and also because of caching. But rest is Stateless (Not saving previous requests.), because of these reasons REST can be used in a lot of public API’s that does not concern about security but needs a high level of speed. For example API to communicate with google maps.

To easily compare the two look at the following table.

REST and SOAP Comparison.

REFERENCES

--

--