SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
Ratpack
Classy and Compact Groovy Web Apps


        James Williams
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
Agenda

● What is Ratpack?
● Routes
● Templates
● Running the App
● Deploying to Servlet Containers
● Deployment
● Demos
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
Ratpack vs Grails
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
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
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
Routes

get("/index") {
  // code
}

post("/login") {
  // code
}

put("/post/:id") {
  // code
}
Routes

get("/index") {
  // code
}

post("/login") {
  // code
}

put("/post/:id") { ==>   /post/3
  // code                  urlparams.id == 3
}
Demo
Authentication
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
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;
    }
}
Creating a Blog App with
        Ratpack
App Essentials

● Simple blog engine

● Uses NoSQL for persistence

● Uses a tweaked Tumblr template

● ~ 156 lines of Groovy code

● Source: http://github.com/jwill/Conference-Demos/user-
  groups
Blog CRUD Routes

get("/post/create") {
render '/post/create.html', [header:header]
}

get("/post/show/:id") {
def post = derby.get(urlparams.id)
render '/post/show.html', [post: post]
}
Blog CRUD Routes (cont'd)

get("/post/list") {
def list = derby.all()
list.sort(sortClosure.curry('dateCreated'))
list = list.reverse()
render '/post/index.html', [posts: list]
}

post("/post/save") {
def post = new Post(params)
derby.save(post.properties, {obj ->
println "Finished saving."
new JSONObject([success:true]).toString()
})
}
Deploying the App
App Structure

/ main/src/groovy
/ templates
/ public
/ lib                   ==> contains Ratpack.jar
/ resources/web.xml   ==> only needed for packaging war
/ build.gradle         ==> contains Ratpack's maven depos
Gradle Application Plugin

● Requires Gradle 1.0+

● Code: plugin 'application'

● Provides common tasks for the application lifecycle.

● Provides the following tasks:
   ○ run

   ○ installApp

   ○ distZip
Gradle File

apply plugin: 'groovy'
apply plugin: 'application'

repositories {
flatDir name:'lib', dirs:'lib'
mavenCentral()
}

dependencies {
groovy group:'org.codehaus.groovy', name:'groovy', version:'1.8.0'
groovy group:'com.bleedingwolf.ratpack', name: 'Ratpack', version:'0.2-SNAPSHOT'
// Ratpack's other dependencies
}
Gradle File (cont'd)

installApp {
into('build/install/'+applicationName){
from ('templates').into '/templates'
}
into('build/install/'+applicationName){
from ('public').into '/public'
}
}
distZip {
into(applicationName){
from ('templates').into applicationName+'/templates'
}
into(applicationName){
from ('public').into applicationName+'/public'
}
}

mainClassName = "BlogApp"
Deploying App as a War
Gradle File Additions

war {
into('/public') {
from('public')
}
into('/templates') {
from('templates')
}
classpath fileTree('lib')
webXml = file('resources/web.xml')
}
Questions ?

Mais conteúdo relacionado

Mais procurados

How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environmentSumedt Jitpukdebodin
 
Provisioning with Puppet
Provisioning with PuppetProvisioning with Puppet
Provisioning with PuppetJoe Ray
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkChristopher Foresman
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJSHüseyin BABAL
 
NodeJS: n00b no more
NodeJS: n00b no moreNodeJS: n00b no more
NodeJS: n00b no moreBen Peachey
 
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Caktus Group
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Derek Willian Stavis
 
Webpack
Webpack Webpack
Webpack DataArt
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundlerAndrea Giannantonio
 
Getting started with node JS
Getting started with node JSGetting started with node JS
Getting started with node JSHamdi Hmidi
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Hervé Vũ Roussel
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsBudh Ram Gurung
 
Vagrant plugin development intro
Vagrant plugin development introVagrant plugin development intro
Vagrant plugin development introBudh Ram Gurung
 
CasperJs Enjoy Functional Testing
CasperJs Enjoy Functional TestingCasperJs Enjoy Functional Testing
CasperJs Enjoy Functional TestingFabien POMEROL
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsRemy Sharp
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 

Mais procurados (20)

Getting started with node.js
Getting started with node.jsGetting started with node.js
Getting started with node.js
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
 
Provisioning with Puppet
Provisioning with PuppetProvisioning with Puppet
Provisioning with Puppet
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST Framework
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 
NodeJS: n00b no more
NodeJS: n00b no moreNodeJS: n00b no more
NodeJS: n00b no more
 
Node ppt
Node pptNode ppt
Node ppt
 
CasperJS
CasperJSCasperJS
CasperJS
 
Composer: Dependency Manager for PHP
Composer: Dependency Manager for PHPComposer: Dependency Manager for PHP
Composer: Dependency Manager for PHP
 
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
 
Webpack
Webpack Webpack
Webpack
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
 
Getting started with node JS
Getting started with node JSGetting started with node JS
Getting started with node JS
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web Applications
 
Vagrant plugin development intro
Vagrant plugin development introVagrant plugin development intro
Vagrant plugin development intro
 
CasperJs Enjoy Functional Testing
CasperJs Enjoy Functional TestingCasperJs Enjoy Functional Testing
CasperJs Enjoy Functional Testing
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 

Semelhante a SF Grails - Ratpack - Compact Groovy Webapps - James Williams

Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRJavier Abadía
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and PracticeBo-Yi Wu
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and MaintenanceJazkarta, Inc.
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to SwaggerKnoldus Inc.
 
How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinSigma Software
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)xSawyer
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausWomen in Technology Poland
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentialsPramod Kadam
 
WordCamp Montreal 2016 WP-API + React with server rendering
WordCamp Montreal 2016  WP-API + React with server renderingWordCamp Montreal 2016  WP-API + React with server rendering
WordCamp Montreal 2016 WP-API + React with server renderingZiad Saab
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & morePower your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & morewesley chun
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebMikel Torres Ugarte
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020Matt Raible
 

Semelhante a SF Grails - Ratpack - Compact Groovy Webapps - James Williams (20)

Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
Dart Workshop
Dart WorkshopDart Workshop
Dart Workshop
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and Practice
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
Revealing ALLSTOCKER
Revealing ALLSTOCKERRevealing ALLSTOCKER
Revealing ALLSTOCKER
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 
How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita Galkin
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentials
 
WordCamp Montreal 2016 WP-API + React with server rendering
WordCamp Montreal 2016  WP-API + React with server renderingWordCamp Montreal 2016  WP-API + React with server rendering
WordCamp Montreal 2016 WP-API + React with server rendering
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & morePower your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Tornadoweb
TornadowebTornadoweb
Tornadoweb
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 

Último

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Último (20)

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

SF Grails - Ratpack - Compact Groovy Webapps - James Williams

  • 1. Ratpack Classy and Compact Groovy Web Apps James Williams
  • 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
  • 9. Routes get("/index") { // code } post("/login") { // code } put("/post/:id") { // code }
  • 10. Routes get("/index") { // code } post("/login") { // code } put("/post/:id") { ==> /post/3 // code urlparams.id == 3 }
  • 11. Demo
  • 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; } }
  • 15. Creating a Blog App with Ratpack
  • 16. App Essentials ● Simple blog engine ● Uses NoSQL for persistence ● Uses a tweaked Tumblr template ● ~ 156 lines of Groovy code ● Source: http://github.com/jwill/Conference-Demos/user- groups
  • 17. Blog CRUD Routes get("/post/create") { render '/post/create.html', [header:header] } get("/post/show/:id") { def post = derby.get(urlparams.id) render '/post/show.html', [post: post] }
  • 18. Blog CRUD Routes (cont'd) get("/post/list") { def list = derby.all() list.sort(sortClosure.curry('dateCreated')) list = list.reverse() render '/post/index.html', [posts: list] } post("/post/save") { def post = new Post(params) derby.save(post.properties, {obj -> println "Finished saving." new JSONObject([success:true]).toString() }) }
  • 20. App Structure / main/src/groovy / templates / public / lib ==> contains Ratpack.jar / resources/web.xml ==> only needed for packaging war / build.gradle ==> contains Ratpack's maven depos
  • 21. Gradle Application Plugin ● Requires Gradle 1.0+ ● Code: plugin 'application' ● Provides common tasks for the application lifecycle. ● Provides the following tasks: ○ run ○ installApp ○ distZip
  • 22. Gradle File apply plugin: 'groovy' apply plugin: 'application' repositories { flatDir name:'lib', dirs:'lib' mavenCentral() } dependencies { groovy group:'org.codehaus.groovy', name:'groovy', version:'1.8.0' groovy group:'com.bleedingwolf.ratpack', name: 'Ratpack', version:'0.2-SNAPSHOT' // Ratpack's other dependencies }
  • 23. Gradle File (cont'd) installApp { into('build/install/'+applicationName){ from ('templates').into '/templates' } into('build/install/'+applicationName){ from ('public').into '/public' } } distZip { into(applicationName){ from ('templates').into applicationName+'/templates' } into(applicationName){ from ('public').into applicationName+'/public' } } mainClassName = "BlogApp"
  • 25. Gradle File Additions war { into('/public') { from('public') } into('/templates') { from('templates') } classpath fileTree('lib') webXml = file('resources/web.xml') }