JVM Web Frameworks Exploration

25
JVM Web Frameworks Exploration Edition by Kevin Tan

Transcript of JVM Web Frameworks Exploration

JVM Web Frameworks

Exploration Edition by Kevin Tan

#intro #shamelessplug

5 years of working experience

#freelance #android #groovy #grailsfw

#springboot #gaelyk

Common Patterns in Web Frameworks

1. Able to go micro (microservices) or full blown2. Layout templating (simplicity of front end coding)3. Able to initialize and bootstrap data in development mode4. Code generation to hasten the development process and reduce the margin

of error5. Non-cryptic error messages6. Supports auto-reloading to some extent7. Ease of deployment8. RESTful (architectural style)

3 JVM Web Frameworks to Learn in 2015/6

BUT FIRST!

Install SDK Manager from Sdkman.io

How SDKMAN Works

Grails

Convention over configuration, sensible defaults, opinionated APIs

Grails 3

Domain as REST Resource

Multi database support in GORM - Postgresql, MySql, MongoDB, etc

Profiles (as of Grails 3.x) - web-api, web-micro, etc

Plugin ecosystem - optional components such as Spring Security Core

Spock testing framework integrated

GSP Layout Templating

Grails 3

@Resource(uri=’/user’, readOnly = false, formats=[‘json’, ‘xml’])

@ToString

class User {

String name

String email

}

Grails 3

grails run-app

DEMO

grails create-app <projectname>

Spring Boot

Opinionated view on building production ready and lightweight Spring applications

Spring Boot

Production ready features - metrics, health checks, app configs, etc.

Can be coded in Java or Groovy, depends on your liking

full blown / micro web

deploys as WAR, JAR or even Groovy script

Any layout templating language you choose such as Thymeleaf, GSP or Groovy template engine

Spring Boot Demo

Start project using http://start.spring.io

For more concrete examples:

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples

Spring Boot Demo

Use the command line:

spring init --list

(to list down the spring components you can initialize with a new project)

then:

spring init --java=1.8 --dependencies=websocket,data-jpa --packaging=war <ProjectName>

https://docs.spring.io/spring-boot/docs/current/reference/html/cli-using-the-cli.html

Ratpack

Lightweight, async non-blocking, unopinionated

Ratpack

Flexible

Metrics integration

Circuit breaker for fault tolerance

Dependency injection

In-built modules such as sessions, auth, etc

Groovy template engine as default layout templating

Ratpack Demo

lazybones create ratpack <project name>

For more concrete examples:

https://github.com/ratpack/example-books

BEST of ALL THREE

Deployable by just using ONE groovy script

Grape Dependency Engine in Groovy (with @Grapes and @Grab )

Netty server / Embedded Tomcat container

Groovy Script Example : Grails

grails create-app <appname> --profile=web-micro

Groovy Script Example : Spring Boot

@RestController

class TestSpringMicro {

@RequestMapping("/")

String home() {

"Hello World!"

}

}

Groovy Script Example : Spring Boot

https://gist.github.com/kevintanhongann/a02016ebf0bea464ec0f

To run, use command ‘spring run <filename>.groovy’

Groovy Script Example : Ratpack

groovy ratpack.groovy for this script written below (You can tweet this!) :

@Grab(‘io.ratpack:ratpack-groovy:1.0.0’)

import static ratpack.groovy.Groovy.ratpack

ratpack {

handlers{

render “Hello world!”

}

}

Groovy script based Microservices?

When to use it??

Prototyping

Hackathons

Production use (code and deploy while production is running) #not100percentsure #perhapsnotsopractical #whoknows

References

Spring Boot - http://projects.spring.io/spring-boot/

Grails - http://www.grails.org/

Ratpack - https://ratpack.io/

Groovy programming language - http://www.groovy-lang.org/