Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Xitrum Web Framework HOWTOs
Scala勉強会 2014/07/11
Ngoc Dao

Takeharu Oshida
With live coding demos
Self intro
http://mobilus.co.jp/archives/306
Xitrum Guidebook
http://xitrum-framework.github.io/guide/en/index.html
http://xitrum-framework.github.io/guide/ja/index.ht...
How to create a new
Scala web project?
xitrum-new
https://github.com/xitrum-framework/xitrum-new
Download project skeleton and explain:
• directory structure
• b...
How to create
Eclipse or IntelliJ
projects?
sbt/sbt eclipse
sbt/sbt gen-idea
• ~/.ivy2
• Scala plugin for Eclipse and IntelliJ

http://scala-ide.org/

http://www.jetb...
How to create a route?
def fib(n: Int): Int = if (n < 3) 1 else f(n - 1) + f(n - 2)
!
---------------------------------------------
!
import xitru...
How to run?
• Run with SBT:

sbt/sbt run
• Run with Eclipse
• Run with IntelliJ
• routes.cache
• log/xitrum.log
• tmp
How to autoreload
classes and routes?
• Run with SBT:

sbt/sbt run

sbt/sbt ~compile
• Run with Eclipse
• Run with IntelliJ
• xitrum.DevClassLoader.ignorePatter...
How to debug?
• Debug with Eclipse
• Debug with IntelliJ
How to create
reverse route?
url[FibAction]("n" -> 3)
• publicUrl("foo.js")
• publicUrl("dir", "foo.js", "foo.min.js")
• webJarsUrl("underscorejs/1.6.0...
How to run
in production mode?
sbt/sbt xitrum-package
!
script/runner <main class>
• XitrumPackage.copy
• Tune memory
• script/start
• http://xitrum-fram...
How to debug
in production mode?
script/scalive
• Oracle JVM is required
• Can't use OpenJDK
How to autogenerate
RESTful API client code?
/xitrum/swagger
• http://xitrum-framework.github.io/guide/en/restful.html#documenting-api
• http://107.167.187.67/xitrum/s...
How to i18n?
t("Hello World")
!
touch i18n.pot
sbt/sbt clean
sbt/sbt compile
• http://xitrum-framework.github.io/guide/en/i18n.html
• h...
How to scale
to multiple servers?
Akka:
clustering code
!
Hazelcast:
clustering data
• http://xitrum-framework.github.io/guide/en/cluster.html
• https://git...
How to monitor
metrics?
/xitrum/metrics/viewer?api_key=xxx
• http://xitrum-framework.github.io/guide/en/metrics.html
• http://107.167.187.67/xitru...
vs Play
Play Xitrum
Netty 3.x 4.x
Hazelcast integration ☓ ○
DB integration ○ ☓
Assets pipeline ○ △
Action types △ ○
Route ...
Upcoming SlideShare
Loading in …5
×

Xitrum HOWTOs

36,667 views

Published on

Xitrum HOWTOs

  1. 1. Xitrum Web Framework HOWTOs Scala勉強会 2014/07/11 Ngoc Dao
 Takeharu Oshida With live coding demos
  2. 2. Self intro http://mobilus.co.jp/archives/306
  3. 3. Xitrum Guidebook http://xitrum-framework.github.io/guide/en/index.html http://xitrum-framework.github.io/guide/ja/index.html
  4. 4. How to create a new Scala web project?
  5. 5. xitrum-new https://github.com/xitrum-framework/xitrum-new Download project skeleton and explain: • directory structure • build.sbt • plugins.sbt
  6. 6. How to create Eclipse or IntelliJ projects?
  7. 7. sbt/sbt eclipse sbt/sbt gen-idea • ~/.ivy2 • Scala plugin for Eclipse and IntelliJ
 http://scala-ide.org/
 http://www.jetbrains.com/idea/features/scala.html • Build Path
  8. 8. How to create a route?
  9. 9. def fib(n: Int): Int = if (n < 3) 1 else f(n - 1) + f(n - 2) ! --------------------------------------------- ! import xitrum.FutureAction import xitrum.annotation.GET ! @GET("fib/:n") class FibAction extends FutureAction { def execute() { val n = param[Int]("n") val ret = fib(n) respondText(ret) } } • Exploratory Coding: sbt/sbt console • Get param from path, URL query, form, header • Action, FutureAction, ActorAction, WebSocketAction, SockJSAciton • respondText, respondJson, respondView etc.
 http://xitrum-framework.github.io/guide/en/action_view.html#respond-to-client
  10. 10. How to run?
  11. 11. • Run with SBT:
 sbt/sbt run • Run with Eclipse • Run with IntelliJ • routes.cache • log/xitrum.log • tmp
  12. 12. How to autoreload classes and routes?
  13. 13. • Run with SBT:
 sbt/sbt run
 sbt/sbt ~compile • Run with Eclipse • Run with IntelliJ • xitrum.DevClassLoader.ignorePattern • xitrum.Config.autoreloadInDevMode
  14. 14. How to debug?
  15. 15. • Debug with Eclipse • Debug with IntelliJ
  16. 16. How to create reverse route?
  17. 17. url[FibAction]("n" -> 3) • publicUrl("foo.js") • publicUrl("dir", "foo.js", "foo.min.js") • webJarsUrl("underscorejs/1.6.0/underscore.js") • webJarsUrl("underscorejs/1.6.0", "underscore.js", "underscore-min.js") • http://xitrum-framework.github.io/guide/en/static.html
  18. 18. How to run in production mode?
  19. 19. sbt/sbt xitrum-package ! script/runner <main class> • XitrumPackage.copy • Tune memory • script/start • http://xitrum-framework.github.io/guide/en/deploy.html
  20. 20. How to debug in production mode?
  21. 21. script/scalive • Oracle JVM is required • Can't use OpenJDK
  22. 22. How to autogenerate RESTful API client code?
  23. 23. /xitrum/swagger • http://xitrum-framework.github.io/guide/en/restful.html#documenting-api • http://107.167.187.67/xitrum/swagger • https://github.com/wordnik/swagger-codegen
  24. 24. How to i18n?
  25. 25. t("Hello World") ! touch i18n.pot sbt/sbt clean sbt/sbt compile • http://xitrum-framework.github.io/guide/en/i18n.html • http://poedit.net/
  26. 26. How to scale to multiple servers?
  27. 27. Akka: clustering code ! Hazelcast: clustering data • http://xitrum-framework.github.io/guide/en/cluster.html • https://github.com/xitrum-framework/xitrum-hazelcast
  28. 28. How to monitor metrics?
  29. 29. /xitrum/metrics/viewer?api_key=xxx • http://xitrum-framework.github.io/guide/en/metrics.html • http://107.167.187.67/xitrum/metrics/viewer?api_key=kgreankbeplawfr7934jv2nr0bsbas0
  30. 30. vs Play Play Xitrum Netty 3.x 4.x Hazelcast integration ☓ ○ DB integration ○ ☓ Assets pipeline ○ △ Action types △ ○ Route autocollection ☓ ○ SockJS ☓ ○ HTML5 CORS ☓ ○ i18n △ ○ Familiar (to Ruby, PHP, Python, Java etc. programmers) △ ○ Others ○ ○ • http://netty.io/wiki/new-and-noteworthy-in-4.0.html

×