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

Context paths

You can now configure the context path by calling app.contextPath("/context-path").
Any requests made below the context path will result in a 404. For example:

  • Java
  • Kotlin
Javalin app = Javalin.create()
    .contextPath("/my-path")
    .enabledStaticFiles("public")
    .port(1234)
    .start()

app.get("/", ctx -> ctx.result("Hello, World"));
val app = Javalin.create().apply {
    contextPath("/my-path")
    enabledStaticFiles("public")
    port(1234)
}.start()

app.get("/") { ctx -> ctx.result("Hello, World") }
GET localhost:1234/                   // 404
GET localhost:1234/my-path            // 200 (Hello, World)
GET localhost:1234/my-path/           // 200 (Hello, World)
GET localhost:1234/script.js          // 404
GET localhost:1234/my-path/script.js  // 200 (if there is a script.js file in your /public folder)

Any argument to contextPath() will be normalized to the form /path (slash, path, no-slash)

@NotNull annotations

All the Java API’s have had @NotNull added to their method signatures, which should provide better IDE support when programming in Kotlin.

Simple safety refactoring

  • Always check if response is committed before trying to write to it
  • Wrap doHandle() in try-catch