Let me walk you through a very simple example of using Ratpack inside Grails.
We start by enabling the Ratpack plugin in our application. I called mine app "example" so all the URLs will be prefixed with "/example". To include the plugin you need to add it to
With that in place we'll create a domain class to have some data to display. I'll go with the simplest possible class that represents a person
Simple enough, right? Let's go an make some use of it in a Ratpack file. Create a folder
grails-app/ratpackand inside of it a file called
As you can see here all we're doing is responding to the GET method on some root URL. Ratpack uses SimpleTemplateEngine from Groovy. We have to tell it where to look for templates
So let's create one to display the people from database
Simple enough, right? It almost looks like a mix of ERB and expression language from JSP. I think you'd have to ask the authors of SimpleTemplateEngine if those similarities have been made on purpose of if this syntax just seemed to be the only one that made sense...
Anyways, with all that in place we can add some people to the database in our
grails-app/conf/BootStrap.groovyfile like this:
And that's it! start the application, navigate to http://localhost:8080/example/ratpack and you should see the list of two people on the screen.
Needless to say you can accomplish the exact same thing using a controller and a view. The idea here however is to show you that there is life beyond the standard artifacts and that the beauty lies in diversity!
Hope this will help someone get started with this awesome piece of code!