Lecture
SOAP (from the English Simple Object Access Protocol) — a protocol for exchanging structured messages in a distributed computing environment. Initially SOAP was intended mainly for implementing remote procedure calls (RPC). Now the protocol is used for exchanging arbitrary XML-format messages, not just for procedure calls. The official specification of the latest version, 1.2, of the protocol does not spell out what SOAP stands for at all .
SOAP is an extension of the XML-RPC protocol.
SOAP can be used with any application-layer protocol: SMTP, FTP, HTTP, HTTPS, etc. However, its interaction with each of these protocols has its own peculiarities that must be defined separately. Most often SOAP is used on top of HTTP.
SOAP is one of the standards that web service technologies are based on.
A SOAP message looks like this:
Example of a SOAP request to an online store server:
Example of a response:

Actually, comparing them is a bit like comparing apples to oranges, since SOAP is an XML-based protocol format, whereas REST is an architectural approach.
REST and SOAP are not really comparable. REST is an architectural style. SOAP is a message exchange format. Let's compare popular implementations of the REST and SOAP styles.
Example of a RESTful implementation: JSON over HTTP
Example of a SOAP implementation: XML over SOAP over HTTP
At a high level, SOAP constrains the structure of your messages, whereas REST is an architectural approach focused on using HTTP as the transport protocol.
The specifics of SOAP lie in the data exchange format. With SOAP it's always SOAP-XML, which is XML that includes:
— Envelope – the root element that defines the message and the namespace used in the document,
— Header – contains message attributes, for example: security information or network routing information,
— Body – contains the message that applications exchange,
— Fault – an optional element that provides information about errors that occurred while processing messages. Both the request and the response must conform to the SOAP structure.
The specifics of REST are in using HTTP as the transport protocol. It implies making the best use of the features HTTP provides — request methods, request headers, responses, response headers, etc.
In SOAP you use the SOAP XML format for requests and responses.
REST has no such fixed format. You can exchange messages based on XML, JSON, or any other convenient format. JSON is the most popular of the formats used.
SOAP uses WSDL (Web Services Description Language) — an XML-based language for describing web services and accessing them.
REST has no standard service definition language. Although WADL was one of the first proposed standards, it isn't very popular. Using Swagger or OpenAPI is more common.
SOAP does not impose any restrictions on the type of transport protocol. You can use either the HTTP web protocol or MQ.
REST implies making the best use of the HTTP transport protocol
RESTful web services are generally much easier to implement than SOAP-based web services.
REST typically uses JSON, which is easier to parse and process. In addition, REST does not require a service definition to be present in order to expose a web service.
With SOAP, however, you need to define your service using WSDL, and there is significant overhead when processing and parsing SOAP-XML messages.
There is also an author's video on this topic.
In this article we took a detailed look at the differences between REST and SOAP.
Comments