REST web service - implementation
On the web there has been a lot of talk about REST (Representational State Transfer) web service. However, it is all on the representational side, its format (mostly, XML output), its usage (use GET, POST), its popularity (very popular, surpassing SOAP because of its simplicity and intutiveness), its champion providers (a lot, including all major internet players, Yahoo, Amazon ... not Google though, google mostly stick to web service) and sample web service (again, all Yahoo service apis are restful service).
However, to find an article on the implementation side of REST is far and bare (actually I do not remember I have seen any). On DNS, we have discussed about this about we are still to find a satisfactory answer.
Is it too complicated to implement? Or the opposite?
I suspect it is the opposite. It might be as easy as its output suggests. REST uses
HTTP
URL
XML
REST has been around as long as the WEB. Every web page is a REST call. In type a web address, out display a web page of information.
Like the age-old HTMLs, REST is stateless, it can be accessed with HTTP GET, POST (all PUT and DELETE, however I am not familiar with these two aspects).
REST responses can be easily found. For example, a local yahoo search call:
And the output xml would be
<?xml version="1.0" ?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/TrafficDataResponse.xsd">
<LastUpdateDate>1215958212</LastUpdateDate>
<Warning>The exact location could not be found, here is the closest match: 701 1st Ave, Sunnyvale, CA 94089</Warning>
- <Result type="construction">
<Title>Road construction, on I-880 at GATEWAY BLVD</Title>
<Description>NORTHBOUNDLONGTERM FULL RAMP CLOSURE CONSTRUCTION</Description>
<Latitude>37.477412</Latitude>
<Longitude>-121.933437</Longitude>
<Direction>N/A</Direction>
<ReportDate>1136610060</ReportDate>
<UpdateDate>1215950340</UpdateDate>
<EndDate>1230792300</EndDate>
</Result>
</ResultSet>
- <!--
ws03.search.re2.yahoo.com compressed/chunked Sun Jul 13 07:12:16 PDT 2008
-->
- The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services.
- Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this
http://www.parts-depot.com/parts/getPart?id=00345
Note the verb, getPart. Instead, use a noun:
http://www.parts-depot.com/parts/00345
3. Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.
4. All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.
5. No man/woman is an island. Likewise, no representation should be an island. In other words, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information
6. Design to reveal data gradually. Don't reveal everything in a single response document. Provide hyperlinks to obtain more details.
7. Specify the format of response data using a schema (DTD, W3C Schema, RelaxNG, or Schematron).
For those services that require a POST or PUT to it, also provide a schema to specify the format of the response.
8. Describe how your services are to be invoked using either a WSDL document, or simply an HTML document.