The best of the descriptions of the difference between the REST and SOAP approaches was found in the book "
Zend Framework: Developing Web Applications in PHP ". I hasten to share with habrovchanami, so that you were armed in case you were asked about the difference between REST and SOAP at an interview
party .
First, look at the difference between the SOAP and REST request and response packets. Here are the SOAP request and response packets:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope" xmlns:ns1="http://rpc.geocoder.us/Geo/Coder/US/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:geocode> <location xsl:type="xsd:string">1600 Pennsylvania Av, Washington, DC</location> </ns1:geocode> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" > <soap:Body> <geocodeREspose xmlns="http://rpc.geocoder.us/Geo/Coder/US/"> <geo:results soapenc:arrayType="geo:GeocoderAddressResult[1]" xsl:type="soapenc:Array" xmlns:geo="http://rpc.geocoder.us/Geo/Coder/US/"> <geo:item xsl:type="geo:GeocoderAddressResult" xmlns:geo="http://rpc.geocoder.us/Geo/Coder/US/"> <geo:number xsl:type="xsd:int">1600</geo:number> <geo:lat xsl:type="xsd:float">38.898748</geo:lat> <geo:street xsl:type="xsd:string">Pensylvania</geo:street> <geo:state xsl:type="xsd:string">DC</geo:state> <geo:city xsl:type="xsd:string">Washington</geo:city> <geo:zip xsl:type="xsd:int">20502</geo:zip> <geo:suffix xsl:type="xsd:string">NW</geo:suffix> <geo:long xsl:type="xsd:float">-77.037684</geo:long> <geo:type xsl:type="xsd:string">Ave</geo:type> <geo:prefix xsl:type="xsd:string"> </geo:item> </geo:results> </geocodeResponse> </soap:Body> </soap:Envelope>
')
Here is the REST request and response:
GET http:
<?xml version="1.0"?> <rdf:RDF xmls:dc="http://purl.org/dc/elements/1.1/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <geo:Point rdf:nodeID="aid47091944"> <dc:description>1600 Pensylvaia Ave NW, Washington DC 20502</dc:description> <geo:long>-77.037684</geo:long> <geo:lat>38.898748</geo:lat> </geo:point> </rdf:RDF>
And now, a great description from the book:
If at any party you are asked a question about the main differences between the SOAP and REST approaches, and an attractive member of the opposite sex will be nearby, this is the answer to this question:
- SOAP makes extensive use of XML to encode requests and responses, as well as strong data typing, ensuring their integrity during transmission between the client and the server. On the other hand, requests and responses in REST can be transmitted in ASCII, XML, JSON or any other formats that can be recognized by both the client and the server. In addition, there are no built-in requirements for data typing in the REST model. As a result, the request and response packets in REST are much smaller than the corresponding SOAP packets.
- In the SOAP model, the HTTP data transfer layer is a “passive observer,” and its role is limited to sending SOAP requests from the client to the server using the POST method. Service request details, such as the remote procedure name and input arguments, are encoded in the request body. The REST architecture, in contrast, treats the HTTP data transfer layer as an active participant in an interaction, using existing HTTP methods, such as GET, POST, PUT, and DELETE, to indicate the type of service requested. Therefore, from a developer’s point of view, REST requests are generally simpler to be formulated and understood, since they use existing and well-understood HTTP interfaces.
- The SOAP model supports a certain degree of introspection, allowing service developers to describe its API in a Web Service Description Language file (WSDL, Web Services Description Language). Creating these files is quite difficult, but it’s well worth the effort, since SOAP clients can automatically retrieve detailed information from these files about the names and method signatures, the types of input and output data, and the return values. On the other hand, the REST model avoids the complexity of WSDL in favor of a more intuitive interface based on the standard HTTP methods described above.
- At the core of REST is the concept of resources, while SOAP uses interfaces based on objects and methods. The SOAP interface can contain an almost unlimited number of methods; the REST interface, by contrast, is limited to four possible operations, corresponding to the four HTTP methods.