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:


  • 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.