Posted by stoicflame
on March 13, 2009 at 3:14 PM PDT
When providing REST resources, consider supporting the AMF media type in addition to your other media types like XML or JSON. This makes life much better for Actionscript/Flex/Flash development. Here's how to write a JAX-RS provider that will write/read resources via AMF.
Over at FamilySearch , I've been involved in supporting Flash application development that consumes a public POX API. It's not a REST API, but like REST, we provide a set of resources that are accessible at a given URI. Up to this point, our Flash developers have been stuck with parsing the resources as XML. It works fine, but it's not without a significant overhead. XML isn't the most efficient data format, nor is it very convenient to work with in ActionScript code.
The "native" data format for flash development is AMF . When ActionScript objects get written to a stream, they are serialized as AMF. When the objects are read from a stream, AMF is the presumed deserialization format. The Enunciate project has provided support for supplying SOAP endpoints as AMF services for quite some time now, but I've only recently added support for AMF REST endpoints.
Here's the wrap-up of the process. As mentioned in the article, if you're already using Enunciate, this process will be significantly simpler. Enunciate already comes with a JAX-RS provider that does the serialization and it will generate your client-side ActionScript classes for you. Not to mention the fact that Enunciate will also generate documentation for your API and neatly package it up, ready to be deployed into your favorite servlet container.