Tuesday, January 18, 2011

Making DevNexus.com more Restful

A few people had ask me, whether I can make the data of DevNexus.com consumable for other clients (e.g. Android or iPhone). Sure, no sweat - As I expose the URL in a somewhat RESTful fashion already, I thought exposing a variety of different data representations is not hard but it turned out to be a bit more tricky than I thought but I will blog about that in the next 1-2 days or so.

Under the covers I am using Spring MVC 3.0 that provides the Rest infrastructure, Jackson for the Json marshalling and Jaxb for marshalling the XML data. 

First of all, here is what I have accomplished: The page that returns a list of presentations and the page that returns a list of speakers, will both return the data in either XML or JSON as well. Bear in mind this is still a fairly rough cut and the data representation may still change quite a bit.

Anyway, these are the exposed endpoints so far:

http://www.devnexus.com/s/presentations
Returns any of the other following 3 data representations depending of the Accept Http header. (However, a defined file extension always wins over the Accept header.)
  • http://www.devnexus.com/s/presentations.html
  • http://www.devnexus.com/s/presentations.xml
  • http://www.devnexus.com/s/presentations.json
http://www.devnexus.com/s/speakers
Returns any of the other following 3 data representations depending of the Accept Http header. (However, a defined file extension always wins over the Accept header.)
  • http://www.devnexus.com/s/speakers.html
  • http://www.devnexus.com/s/speakers.xml
  • http://www.devnexus.com/s/speakers.json 
As Accept headers the following values are acceptable and handled right now:
  • application/xml
  • application/json
  • text/html
For testing the Firefox plugin "Rest Client" works really well:  https://addons.mozilla.org/en-US/firefox/addon/restclient/

As mentioned above, I will blog about the technical details and encountered issues in the next couple of days. Also, if you try to consume the data and run into issues and or have suggestions - ping me and add a comment!

2 comments:

Gunnar Hillert said...

Might be not a good idea to use the Accept header. It turns out I have been running into issues with Webkit based browsers and potentially IE. FF was fine.

Read this article for details:

http://www.gethifi.com/blog/browser-rest-http-accept-headers

Better to set ignoreAcceptHeader=true on my Spring ContentNegotiatingViewResolver.

Configuring my Spring context like in this blog posting does the trick: http://www.rickherrick.com/?q=node/63

Charlie Collins said...

Nice work Gunnar, thanks!