Grails and Flex Presentation for NCDevCon 2010

We just wrapped up the first day at NCDevCon. What a great day and an equally awesome conference. If you missed it you can find all the sessions online, including one that I am partial to, Rapid Development With Grails and Flex ;-)

Video of the Grails and Flex Presentation – http://bit.ly/9yXN1W

Slide deck and source code coming soon.

If you have never written Groovy/Grails then you are really missing out.  Give it a try and check out www.grails.org

I enjoyed the opportunity to present this topic, it was a lot of fun to prepare for and the audience was awesome.  I do want to give special thanks to Jason Rudolph for his guidance and his book Getting Started With Grails – available in free PDF format, but help an author out and purchase the book as well.  We want authors to keep writing and inspiring us.  They can’t keep doing it for free.

I also want to throw a big shout out to all those in the Groovy/Grails Community for providing a fun and useful language and framework.

Flash Player and REST Issue Work Around

RESTful services, ah the thought of leveraging the HTTP protocal to make web service development much simpler than the ‘ole SOAP.  But there is a problem, if you are a Flex or Flash developer that relies on the Flash Player.  You see, staying true to the methodology and spirit of RESTful services means that an HTTP Status Code of 404 actually means something.  It means the resource that was requested was not found.  So in a RESTful service you may call a phone book service that returns a person and their phone number.  Well if that person does not exist the REST service returns an HTTP Status Code of a 404.  Get it? Got it? Okay.

The problem with REST and Flex/Flash is that the Flash player is not able to allow you to write code to handle a status code that falls out side of the 200 range.  If you receive any status code that is not in the 200 range then you receive a fault error.  “If I am calling a REST service and I get something other than a 200 then I can just treat it as a 404,” you say.  Not so fast, what if you get 500 range status code?  Hmm, now what?  Enter, Flex and Javascript together.

Leveraging Javascript with Flex can allow you to handle HTTP Status Codes without having to write server side proxies or having to beg the RESTful Developers to not use status codes as their request response.

Here is how the Javascript and Flex solution would work (here is the source code – JavascriptFlexStatusCodeSolution)

The idea is to use ExternalInterface in Flex to call a Javascript function.  The javascript function makes the call to the RESTful Service. When the response comes back we use javascript to check the status code and then call the appropriate Actionscript code in the SWF file.  Sounds simple?  It is, so download the code and check it out, and hopefully you can get past the status code pain.