|
|
|||||||||||||||||||||||||||||||||||||||||||||
Marc Hadley's Blog
HATEOAS with WADLPosted by mhadley on April 02, 2009 at 09:17 AM | Permalink | Comments (3)Craig asked me how you would describe something like the Sun Cloud APIs with WADL and I thought others might be interested in the answer. A key feature of the cloud APIs is that they make good use of hypertext as the engine of application state or HATEOAS for (relatively) short. What this means is that rather than documenting a set of URIs and URI templates and relying on the client to construct URIs to access the resource they need, the cloud APIs only publish a single "root" URI and then document where to find additional URIs in representations that clients can use to traverse the service. This is much closer to how a browser user traverses links in web pages. In a recent blog entry Craig describes the advantages of HATEOAS. So, how to describe this kind of Web application in WADL ? The key is to:
To illustrate I'll use the Sun cloud APIs and the root level representation of the VDC. In WADL we describe this top level resource as follows: <resources base="http://example.com/"> <resource path="/" type="#vdc"/> </resources> The above declares a top level resource of type "vdc" at the URI "http://example.com/". Next we need to describe the resource type "vdc": <resource_type id="vdc">
<method name="GET">
<response status="200">
<representation mediaType="application/vnd.com.sun.cloud.compute.Vdc+json">
<parameter name="attach" path="vms[].attach" style="plain">
<link resource_type="#button"/>
</parameter>
<parameter name="detach" path="vms[].detach" style="plain">
<link resource_type="#button"/>
</parameter>
<parameter name="backup" path="vms[].backup" style="plain">
<link resource_type="#button"/>
</parameter>
...
</representation>
</response>
</method>
</resource_type>
The above says that a representation of resources of type "vdc" can be obtained with GET and that such representations contain links to other types of resources. I've shown three links here but in reality a VDC document contains many more. Each link is contained within a parameter that describes where in the representation the link can be found. In this case each link is to the same type of resource that essentially acts like a push button, here's the description of that resource type: <resource_type id="button"> <method name="POST"> <response status="204"> </method> </resource_type> The above says that resources of type "button" only support POST and return an empty 204 response on success. I've glossed over one important issue related to the use of JSON for the representation of a VDC. If the representation used XML then the value of the path attribute of the parameter element is an XPath and it has semantics for selecting a set of nodes. For JSON theres no such standard path language (that I'm aware of) so I've had to improvise. The "vms" property of the vdc JSON object is an array and the "[]" in the path attribute values is meant to signify that the path will match multiple properties of the JSON object, if anyone has a better idea then let me know. JAX-RS 1.1 Draft AvailablePosted by mhadley on March 13, 2009 at 09:27 AM | Permalink | Comments (0)A draft of the JAX-RS 1.1 specification and API is now available. We're now working on implementing the new features in Jersey and adding corresponding tests to the TCK. It will be a while before 1.1 can be declared final since there's quite a bit of new functionality, particularly in the areas of integration with Servlet 3.0, EJB 3.1 and JSR 299 - none of which are yet final. |
June 2009
Search this blog:CategoriesCommunity: Java Web Services and XMLCommunity: Mac Java Community Distributed J2EE J2SE Programming Web Services and XML Archives
April 2009 Recent Entries | ||||||||||||||||||||||||||||||||||||||||||||
|
|