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

CORS

Javalin 0.4.0 adds built-in CORS support with app.enableCorsForOrigin("origin"). There were also some breaking changes made to Jackson and the template-engines. If you want to configure Jackson now, you’ll have to call JavalinJacksonPlugin.configure() instead of just Jackson.configure().

0.3.0 to 0.4.0 recap

  • Added simple file-upload api:
    app.post("/upload") { ctx ->
      ctx.uploadedFiles("files").forEach { (contentType, content, name, extension) ->
          FileUtils.copyInputStreamToFile(content, File("upload/" + name))
      }
    }
    
  • Added ctx.mapQueryParams() and ctx.mapFormParams(), which adds neat destructuring in Kotlin:
    app.post("/new-user") { ctx ->
      val (name, email) = ctx.mapFormParams("name", "email") ?: throw MissingFormParamException()
    }
    
  • Added ctx.anyQueryParamNull() and ctx.anyFormParamNull() for Java devs who can’t destructure
  • Added option to declare routes without paths, relying on the path() method:
    app.routes {
      path("users") {
          get(userController::getAllUsers);
          post(userController::createUser);
          path(":id") {
              get(userController::getUser);
              patch(userController::updateUser);
              delete(userController::deleteUser);
          }
      }
    }
    
  • Added support for external static files via app.enableStaticFiles("/folder", Location.EXTERNAL)
  • app.start() and app.stop() are now synchronous methods (app.awaitStart() and app.awaitStop() have been removed)
  • Added @JvmStatic annotations, so INSTANCE can be omitted when calling configuration-methods from Java
  • Added option to dontIgnoreTrailingSlashes()
  • Added some convenience methods and overloads (like start(port) and render(templatePath))

There were also other minor adjustments and bugfixes, see the news overview for a complete list.