Javalin is a web framework for Java and Kotlin which is simple, lightweight, interoperable, and flexible.
With the major changes introduced in the codebase, the team has now announced the release of Javalin 2.0 RC3. Some of the updates include removal of some abstraction layers, using Set instead of List, removal of CookieBuilder, Javalin lambda replacing Javalin Jetty, and more.
Updates in the Javalin 2.0 RC3
Package structure improvements
The following table lists the packages whose structure have been updated in this release:
|Javalin 1.7||Javalin 2.0 RC3|
Changes in the server defaults
- Earlier, when we wanted to customize our embedded server, we used to write the following:
app.embeddedServer(new EmbeddedJettyFactory(() -> new Server())) // v1
Now with the removal of embedded server abstraction, we can directly write this:
app.server(() -> new Server()) // v2
- Since the static method Javalin.start(port) has been removed, use Javalin.create().start(0) instead.
- defaultCharset() method has been removed
The following are enabled by default:
- Dynamic gzip, turn it off with disableDynamicGzip()
- Request-caching is now limited to 4kb
- Server now has a LowResourceMonitor attached
- URLs are now case-insensitive by default, meaning Javalin will treat /path and /Path as the same URL. This can be disabled with app.enableCaseSensitiveUrls().
Javalin lambda replaces Jetty WebSockets
Since Jetty WebSockets have limited functionality, it is now replaced with the Javalin lambda WebSockets.
This is an interface used to set per-endpoint authentication and authorization. Use Set instead of List. It now runs for every single request, but the default-implementation does nothing.
Context is the object, which provides you with everything needed to handle an http-request.
The following updates are introduced in Context:
- ctx.uri() has been removed, it was a duplicate of ctx.path()
- ctx.param() is replaced with ctx.pathParam()
- ctx.xyzOrDefault(“key”) are changed to ctx.xyz(“key”, “default”)
- ctx.next() has been removed
- ctx.request() is now ctx.req
- ctx.response() is now ctx.res
- All ctx.renderXyz methods are now just ctx.render(), since the correct engine is chosen based on extension
- ctx.charset(charset) has been removed
- You can use the Cookie class in place of CookieBuilder, as it is now removed
- Now List
is returned instead of Array
- Things that used to return nullable collections now return empty collections instead
- Kotlin users can now do ctx.body
() to deserialize json
In this article we looked at some of the major updates in Javalin 2.0. To know more, head over to their GitHub repository.