While the end goal is the same, REST and SOAP cannot be directly compared as REST is a set of guidelines that developers may choose to implement differently from project to project while SOAP is a well defined and standardized protocol for data exchange.auth0
REpresentational State Transfer (REST) is a software architecture that was designed to operate over a world-wide network. Some of the core architecture principles are:
- Layered abstraction between a resource (thing that manages objects) and object (e.g., database, file, etc.)
- Lightweight (“loose”) coupling between the client and the server, addressing over the network through URIs
- Easy to understand resource representation
The layered abstraction allows for the object implementation to be hidden from the requesting entity. This means that the underlying implementation can change on the resource side without impacting any other endpoint. Abstraction is a common software practice and REST takes abstraction to be at the application layer.
Clients (or user agents) are decoupled from the server as much as possible. This means that neither end point needs to have a tight coupling on implementation or interface. Moreover, addressing is done through a Uniform Resource Identifier (URL is an example of a URI) which allows for flexible identification of endpoints.
Working with a resource is easy to understand as it is in plain text for requests and responses.
How is REST used
A web service that follows REST practices has a “RESTful” interface. Web resources are made accessible through the URI. This mean that HTTP GET/PUT/POST/DELETE operations are valid on these resources. Data is exchanged either using JSON, HTML, or XML.
Considerations for REST
- Freedom to implement as needed
- Easier to implement because of flexibility (lack of explicit protocol implementation)
- Entities are accessible through URIs and interaction is with those entities directly
- HTTP allows for cached results which could be used to speedup response times
- Integration with other apps requires work as there is no defined standard
- Only used over HTTP
- No explicit security protocol or considerations
SOAP used to stand for Simple Object Access Protocol but that name was abandoned prior to the 1.2 release. SOAP is a message protocol meaning it defines the rules, syntax, semantics and synchronization for communication. SOAP consists of a prescribed SOAP-envelope which defines the information as a SOAP message. Inside the SOAP message can be a SOAP-header and will contain a SOAP-body. The SOAP-body defines the call and response information.
A RESTful interface can use SOAP. But it doesn’t make sense to say SOAP uses REST; SOAP is a protocol that can be used in a REST architecture. See the table in  for a great breakdown between SOAP and REST.
How is SOAP used
SOAP is used over application-layer protocols such as SMTP, HTTP, HTTPS. It only uses XML as the data format. SOAP has extensions for expansion including WS-Security. Endpoints that communicate via SOAP exchange Web Service Description Language (WSDL) files which describe the endpoint resources and operations.
Considerations for SOAP
- Standardized message format lends itself to reusable development, testing and debugging practices
- Expandable to include security practices
- Expandable to be stateful
- XML is beefy and thus the message exchange between endpoints has a longer latency
- When the resource changes, a new WSDL file needs to be provided to 3rd parties to integrate
- Service interfaces are used to access entities and interactions go through a middle-layer