REST v/s SOAP

In this article, we will compare between REST and SOAP web services in detail i.e.; REST v/s SOAP

Before diving into detail for comparison, quickly go through below articles for different types of web services in Java platform

 

There are 2 types of Web Services

  • REST (REpresentational State Transfer)
  • SOAP (Simple Object Access Protocol)

 

 REST (JAX-RS based web services)

 

SOAP (JAX-WS based web services)

 

Here are the difference between REST web service and SOAP web service in tabular form;

REST SOAP
 REST is an architecture style SOAP is a protocol
 REST –> REpresentational State Transfer SOAP –> Simple Object Access Protocol
Generally, REST web services are exposed using URI i.e.; Uniform Resource Identifier  SOAP web services are exposed using WSDL document (i.e.; Web Service Definition Language) via Service Endpoint Interface (SEI)
JAX-RS (Java API for RESTful Web Services) is the specification for building/developing REST web services JAX-WS  (Java API for XML Web Services) is the specification for building/developing SOAP web services
For different CRUD operations like insert/select/update/delete, different HTTP 1.1 methods are available i.e.;

  • POST –> insert operation
  • GET –> retrieve operation
  • PUT –> update operation
  • DELETE –> delete operation
There are no such methods available for SOAP web services

Only contract is exposed to outside world through WSDL document which could be any operations (depends on underlying developer or designer’s implementation)

Client and Server exchange information (i.e.; request and response) in one of the following formats

  • JSON
  • XML
  • Plain Text
  • HTML
Client and Server exchange information (i.e.; request and response) only one format i.e.; XML
REST requires less bandwidth and resource compared with SOAP, as most of the time request /response exchanges in JSON format SOAP requires more bandwidth and resource, as request/response exchanged only in XML format
REST resources exchange information mostly in JSON format, therefore its request and response processed faster comparing with SOAP SOAP messages (i.e.; request and response) are processed slower compared with REST, as SOAP supports only XML format
REST doesn’t defines any such standards like SOAP but it defines conventions like HTTP PUT for update, HTTP POST for insert, etc SOAP defines standard set of protocols which needs be followed strictly, otherwise raising exception (i.e.; soap faults)
REST depends on underlying transport for security purposes SOAP defines its own security, as it is standardized through WS-Security

Note: Highly secure comparing with REST

REST is very easy to implement and it is highly preferred among developers community SOAP isn’t that easy to implement, when comparing with REST
Uses web caching mechanism, as REST is URL based Ignores web caching mechanism
As REST is purely based on URI, just if there are any changes then corresponding changed URL need to be exchanged (much simpler v/s SOAP) Maintenance, if there is any change in the WSDL then we need to generate client stub again
Not suitable for distributed computing Very good fit for distributed computing environment
Example: It is used for light-weight application like mobile application or where processing required at very high speed Example: Generally, it is used in large enterprise application like Telecom, finance, etc where request/response pattern is complex
Various vendor implementation for REST web service,

Different vendor implementation for SOAP web service,

 

Best design practice for choosing REST v/s SOAP:

  • SOAP: Whenever there are external system/applications  (third-party applications) to interact with our system/applications, then it is always preferred to go for SOAP as it has got in-built ws-security features
  • REST: And whereas for internal system/applications (or intra-application interaction within our organization), then it is preferred to go for REST web services as it will be faster

Note: It is like choosing security over faster processing or vice-versa and it all depends upon business requirements

 

 

Happy Coding !!
Happy Learning !!

Web Service clients