ratpack 101 - gr8conf 2015

28
@alvaro_sanchez Ratpack 101 @alvaro_sanchez Álvaro Sánchez-Mariscal - Web Architect

Upload: alvaro-sanchez-mariscal

Post on 28-Jul-2015

560 views

Category:

Software


0 download

TRANSCRIPT

@alvaro_sanchez

Ratpack 101@alvaro_sanchez

Álvaro Sánchez-Mariscal - Web Architect

@alvaro_sanchez

About me

● Passionate Software Developer.○ Former BEA/Sun instructor, Groovy fanboy since 2006.

● Speaker at Codemotion, JavaLand, GeeCON, Spring IO, GR8Conf, GGX and Greach.

● Author of several Grails plugins.● Working now at as a Web Architect.

@alvaro_sanchez

About

● HTML5 platform for gambling games.● We provide game developers a Javascript SDK. ● Server side logic and maths are handled by our

industry certified game engines.● Seamless integration with several casinos.● Check out play.odobo.com and play for free!

@alvaro_sanchez

Workshop requirements

● JDK 8 (both in command line and in your IDE).● Git.● Gradle.● Groovy 2.4.1+ (on the command line).● Lazybones installed via GVM.

@alvaro_sanchez

Slides, code and workshop available

● Slides:○ http://bit.ly/ratpack-101-slides

● Companion code:○ http://bit.ly/ratpack-101-code

● Workshop:○ http://alvarosanchez.github.io/ratpack-101

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

Introduction● Ratpack is:

○ A set of Java 8 libraries…○ … lightweight, un-opinionated, Netty-based... ○ … for writing non-blocking HTTP applications…○ … focused on performance and efficiency…○ … with an emphasis on testability..

○ … embracing Java 8 or Groovy as programming

languages.

@alvaro_sanchez

When to use Ratpack?

● For microservices.● For high performance applications.● For lightweight services (no container,

batteries included).

@alvaro_sanchez

Ratpack is developer friendly

● Startup in milliseconds.● Development-time reloading with Spring

Loaded.● First-class support for functional testing.

@alvaro_sanchez

Exercises

1. Hello World using a Groovy script (15 minutes).

2. Creating Ratpack projects with Lazybones and running them with Gradle (10 minutes).

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

Handlers

● An incoming request is passed through the handler chain.

● A handler can:○ Respond to the request.○ Delegate to the next handler in the chain.

○ Insert more handlers in the chain and delegate to

them.

@alvaro_sanchez

Handlers

● Each handler is given a Context instance.○ To interact with the request / response objects.○ To access the registry.○ Etc.

● Note that Ratpack is not based on the Servlet API.

@alvaro_sanchez

Exercises

3. Working with handlers (30 minutes).4. Testing Ratpack applications with Spock (20

minutes).

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

The Context● The Context provides:

○ Access to the HTTP Request and Response objects.

○ Interaction with other handlers through next() and

insert() methods.○ Access to objects in the registry.

@alvaro_sanchez

The registry

● The context is also a Registry of objects.● Handlers can store objects into the context for

use by downstream handlers.

@alvaro_sanchez

Exercises

5. Working with the context (20 minutes).

@alvaro_sanchez

Agenda

● Introduction.● The handlers chain.● The context.● Ratpack modules.● Q&A.

@alvaro_sanchez

Ratpack modules

● Ratpack can integrate with Google Guice for:○ Dependency injection for services, etc.○ Officially supported modules.○ Reusing your own components as your modules.

@alvaro_sanchez

Official modules (1/2)● Benchmarks (JMH).● Metrics.● H2 Database.● Handlebars.● HikariCP JDBC pool.● Hystrix.

● Jackson.● New Relic.● Pac4J.● Reactor.● Groovy Remote

Control.

@alvaro_sanchez

Official modules (2/2)● RxJava.● HTTP Sessions.● Spring Boot.● Thymeleaf.

@alvaro_sanchez

Exercises

6. Using Ratpack modules with Google Guice (20 minutes).

@alvaro_sanchez

Álvaro Sánchez-Mariscal

Web Architect - odoboImages courtesy of

Tak!