Monday, September 19, 2011

About Rest and the Web



 Representational State Transfer or rest is the simplest terms is a way of accessing and modifying resources in a format that is easily understood. I, like many, though it was just how HTTP sends and receives data for a browser to render. Didn't know there was so much more to the story.

Awesome layman's explanation. I highly recommend you get that first coffee and get comfortable before embarking on this one. If it wasn't as interesting a read it would certainly be in the TL;DR category.

http://tomayko.com/writings/rest-to-my-wife

After this I began to wonder the the heck was the point of SOAP requests
and I was not the only one.

http://stackoverflow.com/questions/686634/soap-whats-the-point


I mean look at a Rest request and response.
*material found here (http://www.jmarshall.com/easy/http/#structure)*

Request:To retrieve the file at the URL:

http://www.somehost.com/path/file.html

GET /path/file.html HTTP/1.0
From: someuser@jmarshall.com
User-Agent: HTTPTool/1.0
[blank line here]

Response:The server should respond with something like the following, sent back through the same socket

HTTP/1.0 200 OK
Date: Fri, 31 Dec 1999 23:59:59 GMT
Content-Type: text/html
Content-Length: 1354

<html>
<body>
<h1>Happy New Millennium!</h1>
(more file contents)
  .
  .
  .
</body>
</html>

And take a look at request and response in Soap


Request: GetStockPrice request is sent to a server. The request has a StockName parameter

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>

Response:a Price parameter that will be returned in the 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>


While Lines of code != Complexity in all cases, I think it would be a fair way of summarizing this particular one.

Additional comparison notes on Wikipedia
http://en.wikipedia.org/wiki/REST#SOAP_RPC_contrast


No comments: