xitrum howtos
DESCRIPTION
TRANSCRIPT
Xitrum Web Framework HOWTOs
Scala勉強会 2014/07/11Ngoc Dao
Takeharu Oshida
With live coding demos
Xitrum Guidebookhttp://xitrum-framework.github.io/guide/en/index.html http://xitrum-framework.github.io/guide/ja/index.html
How to create a new Scala web project?
xitrum-newhttps://github.com/xitrum-framework/xitrum-new
Download project skeleton and explain: • directory structure • build.sbt • plugins.sbt
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.jetbrains.com/idea/features/scala.html
• Build Path
How to create a route?
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
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 runsbt/sbt ~compile
• Run with Eclipse • Run with IntelliJ
• xitrum.DevClassLoader.ignorePattern • xitrum.Config.autoreloadInDevMode
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/underscore.js") • webJarsUrl("underscorejs/1.6.0", "underscore.js", "underscore-min.js") • http://xitrum-framework.github.io/guide/en/static.html
How to run in production mode?
sbt/sbt xitrum-package !
script/runner <main class>
• XitrumPackage.copy • Tune memory • script/start • http://xitrum-framework.github.io/guide/en/deploy.html
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/swagger • https://github.com/wordnik/swagger-codegen
How to i18n?
t("Hello World") !
touch i18n.pot sbt/sbt clean sbt/sbt compile
• http://xitrum-framework.github.io/guide/en/i18n.html • http://poedit.net/
How to scale to multiple servers?
Akka: clustering code !
Hazelcast: clustering data
• http://xitrum-framework.github.io/guide/en/cluster.html • https://github.com/xitrum-framework/xitrum-hazelcast
How to monitor metrics?
/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
vs PlayPlay Xitrum
Netty 3.x 4.xHazelcast 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