⬆️ ⬇️

REST vs SOAP

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://geocoder.us/service/rest/geocode?address=1600+Pennsylvania+Ave,+Washington+DC 


 <?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:



Source: https://habr.com/ru/post/158605/



All Articles