1

I am trying to understand the different between SOAP and REST so one of these differences is. SOAP exposes operation that represents logic and REST exposes Resources that represent data. What does that mean? Can someone clarify that with examples?

1

SOAP is a standardized communications protocol.

A SOAP request:
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>

The SOAP response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPriceResponse>
    <m:Price>34.5</m:Price>
  </m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>    

Notice that you're passing data to a SOAP endpoint, and it's returning data in response. The action is governed entirely by the XML that defines the SOAP protocol. Also notice that a POST is being used, so this could, in fact, be a REST-style endpoint.

REST is an architectural style, not a communications protocol.

REST is an understanding that endpoints represent resources, and some mechanisms that promote that understanding. REST endpoints are entirely agnostic about the kind of data that is passed back and forth between them; you can have SOAP data, XML data associated with AJAX, JSON, or pretty much anything else.

Further Reading
What is REST?
SOAP Example
How I Explained REST to my Wife

1

SOAP follows the Remote Procedure Call paradigm. REST follows, well the REST paradigm. A better question is difference between SOAP and HTTP (SOAP uses HTTP completely wrong)

In simple terms RPC is when a client makes a call over the network to a server in order to issue a command on the server. So a client might say "Hey server, update stock price to be 10 euro a share" or "Hey server, compute the fibonati sequence"

A problem with RPC is that it couples the client and server quite strongly together. The client must know what calls it can make to the server, and if you update the server you must update the clients as well, even if are just changing the name of a remote procedure.

REST is a different way to thinking about communication between servers that implements strict restrictions that ironically increase flexibility.

With REST the communication between client and server is concerned ONLY with transferring the state of a resource between the client and the server. HTTP protocol is a REST protocol and you will notice there are only a handful of actual commands you can call on the sever (GET, PUT, POST, DELETE etc). You cannot (or should not) ask the server to run any other commands.

In REST a client says "Hey I want to do something with resource X, so give me a copy of it". The client then does what ever it wants to do and then says to server "Hey I'm done with updating that resource, here is it's new state please update yourself"

The advantage of this is that clients and servers have to know very little about each other, they just need to know that both support the REST protocol such as HTTP 1.1, and they have to understand the Content Type of the resources, at least on the client side (sometimes on server side as well if you want server to validate new state before it saves it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.