Slides for SF Grails meetup.
Ratpack, a micro web framework for Groovy, "inspired by the excellent Sinatra framework for Ruby, aims to make Groovy web development more classy."
We are happy to have James Williams (Co-Creator of Griffon) to be presenting!
2. About Me
● Co-founder of Griffon
● Author of "Learning HTML5
Game Programming"
http://amzn.to/HTML5-Game-Book
● Blog: http://jameswilliams.be
● Twitter: @ecspike
● G+: http://gplus.to/ecspike
3. Agenda
● What is Ratpack?
● Routes
● Templates
● Running the App
● Deploying to Servlet Containers
● Deployment
● Demos
4. What is Ratpack?
● Apache 2 Licensed
● Inspired by Sinatra (Ruby)
● Logic is largely driven by Routes
● Powered by Jetty
● Built-in support for Groovy SimpleTemplateEngine
● Github: https://github.com/bleedingwolf/Ratpack
6. When to use Grails...
● Data-driven model
● Large number of models with differing endpoints
● Spring Security is a definite need
● Out of the box persistence integration is required
● Plan to make great use of the Grails plugin ecosystem
7. When to use Ratpack...
● Low number of domain classes
● Limited number of routes/endpoints
● Model - View - Controller paradigm is not needed
● Small but evolving REST API
8. Routes
● Composed of a HTTP verb, an endpoint, and a code block
● Verb can be one of the nine canonical verbs or you can
create your own
● Endpoint corresponds to URL fragment.
● :<identifier> injects that value into the urlparams object
● Code block is injected with:
○ request
○ response
○ renderer
○ urlparams
13. Basic Authentication
● Client-side:
○ Username and password are concatenated separated by
a colon
○ Resulting string is base 64 encoded
○ Attached to request header
● Server-side:
○ Header is pulled from request
○ Decoded
○ Validated
○ Sends response
14. Basic Authentication
class Auth {
static doAuth = {app ->
def handler = { req ->
def authHeader = req.getHeader("Authorization")
def encodedValue = authHeader.split(" ")[1]
def decodedValue = new String(encodedValue.decodeBase64())?.split(":")
// do some sort of validation here
if (decodedValue[0] == "") {
return "Unauthorized"
} else {
decodedValue
}
}
app.metaClass.doAuth = handler;
}
}