Top Banner
JVM Web Frameworks Exploration Edition by Kevin Tan
25

JVM Web Frameworks Exploration

Apr 12, 2017

Download

Technology

Kevin H.A. Tan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JVM Web Frameworks Exploration

JVM Web Frameworks

Exploration Edition by Kevin Tan

Page 2: JVM Web Frameworks Exploration

#intro #shamelessplug

5 years of working experience

#freelance #android #groovy #grailsfw

#springboot #gaelyk

Page 3: JVM Web Frameworks Exploration

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)

Page 4: JVM Web Frameworks Exploration

3 JVM Web Frameworks to Learn in 2015/6

Page 5: JVM Web Frameworks Exploration

BUT FIRST!

Install SDK Manager from Sdkman.io

Page 6: JVM Web Frameworks Exploration

How SDKMAN Works

Page 7: JVM Web Frameworks Exploration

Grails

Convention over configuration, sensible defaults, opinionated APIs

Page 8: JVM Web Frameworks Exploration

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

Page 9: JVM Web Frameworks Exploration

Grails 3

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

@ToString

class User {

String name

String email

}

Page 10: JVM Web Frameworks Exploration

Grails 3

grails run-app

Page 11: JVM Web Frameworks Exploration

DEMO

grails create-app <projectname>

Page 12: JVM Web Frameworks Exploration

Spring Boot

Opinionated view on building production ready and lightweight Spring applications

Page 13: JVM Web Frameworks Exploration

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

Page 14: JVM Web Frameworks Exploration

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

Page 15: JVM Web Frameworks Exploration

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

Page 16: JVM Web Frameworks Exploration

Ratpack

Lightweight, async non-blocking, unopinionated

Page 17: JVM Web Frameworks Exploration

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

Page 18: JVM Web Frameworks Exploration

Ratpack Demo

lazybones create ratpack <project name>

For more concrete examples:

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

Page 19: JVM Web Frameworks Exploration

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

Page 20: JVM Web Frameworks Exploration

Groovy Script Example : Grails

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

Page 21: JVM Web Frameworks Exploration

Groovy Script Example : Spring Boot

@RestController

class TestSpringMicro {

@RequestMapping("/")

String home() {

"Hello World!"

}

}

Page 22: JVM Web Frameworks Exploration

Groovy Script Example : Spring Boot

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

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

Page 23: JVM Web Frameworks Exploration

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!”

}

}

Page 24: JVM Web Frameworks Exploration

Groovy script based Microservices?

When to use it??

Prototyping

Hackathons

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

Page 25: JVM Web Frameworks Exploration

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/