Mastering Grails: RESTful Grails (Scott Davis)
Rails, Scott Davis September 19th, 2008
Developerworks has published the ninth chapter of Scott’s Mastering Grails series: RESTful Grails.
This month, I’m going to show how your Grails applications can be a source of raw data — specifically, XML — that other Web applications can use. I’d normally describe this as setting up Web services for your Grails application, but the term is loaded with hidden meanings these days. Many people associate Web services with SOAP and a full-blown service-oriented architecture (SOA). Two plug-ins for Grails allow you to expose a SOAP interface to your application if you choose that route. But rather than deal with a specific implementation such as SOAP, I’ll show you how to return Plain Old XML (POX) using an interface based on Representational State Transfer (REST).
When it comes to RESTful Web services, it’s as important to understand the why as much as the how. Roy Fielding’s doctoral dissertation — the source of the REST acronym — outlines two approaches to Web services: one that’s service-oriented and another that’s resource-oriented. Before I show you the code to implement your own RESTful resource-oriented architecture (ROA), I’ll clarify the differences between these two design philosophies, and I’ll discuss the two competing definitions of REST in popular usage. As your reward for taking in all the talk in the first part of this article, you’ll find plenty of Grails code later on.
Scott sheds some light on the SOAP vs REST debacle, which interestingly enough is similar to the “essence vs ceremony” one found in the language arena. After a bit of theory he dives head first into implementing RESTful services with Grails, which is really quite simple. If you are expecting to see tons of configuration, myriads of line of code and probably tools that help you deal with ugly pointy files (a.k.a XML) then you are int for a suprise, no such thing in Grails! This article will walk you over implementing each of the 4 REST verbs (GET, DELETE, POST, PUT) one after the other, while showing possible extension points you may exercise in your application to enhance the end user experience and still keep your a readable codebase. Enjoy!
Tags: Rails, Scott Davis
About