Griffon: adding REST - No Fluff Just Stuff

Griffon: adding REST

Posted by: Andres Almiray on October 13, 2009

Creating REST enabled Swing mashups just got a bit easier. I'm happy to announce that a REST plugin is now available for Griffon. This plugin wraps handy client and builder classes provided by the awesome HTTPBuilder project.

Let me walk you through a simple example. It seems that nowadays a Twitter demo is the way to go so let's follow that path. We'll build a trivial application that will query the followers of an authenticated user, these are the steps:
  1. First, grab a copy of Griffon 0.2-BETA (or newer) if you haven't done so already.

  2. Let's create the app, type griffon create-app gritter on your command prompt.

  3. Go into the app's directory and type griffon install-plugin rest, this will install the latest version of the REST plugin.

  4. Edit griffon-app/models/GritterModel.groovy by adding the following text

  5. Edit griffon-app/views/GritterView.groovy, add the following text

  6. Fetch a copy of GlazedLists and MigLayout and place them inside $basedir/lib. That should take care of all required dependencies.

  7. Edit griffon-app/controllers/GritterController.groovy, this is where the magic happens
    The Rest plugin will inject a few dynamic methods, withRest() is one of them. This method uses a RESTClient under the covers. Notice that the Twitter request is performed outside the EDT, followers are collected on a background thread, then the model is updated inside the EDT.

  8. Run the application by typing griffon run-app. Upon entering valid Twitter credentials you should see a similar screen like the following one



  9. That's it! The plugin comes with other nifty features like reusable clients (using an id: property) and proxy settings shortcuts. Feedback is always appreciated.

    Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »