As a developer we might have worked on REST as well as SOAP based services. However when it comes to decide which one to use then many developers are not very clear with the answer. Let’s see in this article what are the differences in these two ways of creating web services. Before we dig-down into the differences here is a short history about REST and SOAP.
REST: REST(representational state transfer) was introduced and defined in 2000 by Roy Thomas Fielding in PhD dissertation “Architectural Styles and the Design of Network-based Software Architectures”. Rest facilitates philosophy of open web.
SOAP: SOAP(Simple Object Access Protocol) was introduced in 1998 by Dave Winer in collaboration with Microsoft. SOAP is mainly used to address the goals of the enterprise market.
Basic Concept
| REST | SOAP |
| Makes data available as a resources. E.g. AccountInformation, Invoice | Makes application logic available as a servies. E.g. getAccountInformation, PayInvoice |
| It’s an architectural style. | It’s a protocol. |
Advantages
| REST | SOAP |
| It uses standard HTTP. Hence easy to implement. | Works on top of any communication protocol |
| Returns data in many different formats (JSON,XML etc.) | It can be fully described using WSDL |
| Better performance and scalability. Reads can be cached. | Provides end-to-end reliability and successful/retry logic is built in |
| REST allows better support for browser clients due to its support for JSON. | Security and authorization are part of protocol |
Disadvantages
| REST | SOAP |
| Only works on top of HTTP protocol | Hard to implement and not so popular among web and mobile developers |
| No built-in standards for security or reliability | Permits XML data format only |
| No constraints on the payload | SOAP defines standards to be strictly followed. |
| Requires more bandwidth and resource than REST. |
When to use what
| REST | SOAP |
| When your bandwidth is very limited. | When performing transactions that involves multiple calls. |
| When client and server operates on a web environment | When you want to enforce a strict contract between client and server |
| Examples: Social Media Service, Web chat service | Examples: Financial services, telecommunication services |
In nutshell , identify your project need and goal you want to achieve before you pick any of the approaches.