Important: This news article covers an old version of Javalin (v0.3.0). The current version is v6.1.3.
See the documentation page for up-to-date information.

Javalin 0.3.0 changes the core API from dealing with request/response pairs, to just dealing with a single context(or ctx) object. This context-object contains all the methods that belonged to request and response previously, with a few adjustments:

Comparison:

  • Java
  • Kotlin
app.get("/", ctx -> ctx.result("Hello World")); // new syntax
app.get("/", (req, res) -> res.body("Hello World")); // old syntax
app.get("/") { ctx -> ctx.result("Hello World") } // new syntax
app.get("/") { req, res -> res.body("Hello World") } // old syntax

Most getters (header(name), cookie(name), etc) operate on the underlying request, while all setters (header(name, value), cookie(name, value), etc) operate on the underlying response. Since request and response don’t share any methods, this approach seems to work well.