Fork me on GitHub

Simple REST APIs for Java and Kotlin

Get your REST API up and running in seconds. Add the dependency and copy example:

import io.javalin.Javalin;

public class HelloWorld {
    public static void main(String[] args) {
        Javalin app = Javalin.start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
import io.javalin.Javalin

fun main(args: Array<String>) {
    val app = Javalin.start(7000)
    app.get("/") { ctx -> ctx.result("Hello World") }

REST API Simplicity

Javalin started as a fork of the Spark Java and Kotlin web framework but quickly turned into a ground-up rewrite influenced by koa.js. All of these web frameworks are inspired by the modern micro web framework grandfather: Sinatra, so if you’re coming from Ruby then Javalin shouldn’t feel too unfamiliar.

Javalin is not aiming to be a full web framework, but rather just a lightweight REST API library. There is no concept of MVC, but there is support for template engines, websockets, and static file serving for convenience. This allows you to use Javalin for both creating your RESTful API backend, as well as serving an index.html with static resources (in case you’re creating an SPA). This is practical if you don’t want to deploy to apache or nginx in addition to your Javalin service. If you wish to use Javalin to create web-pages instead of just REST APIs, there are some simple template engine wrappers available for a quick and easy setup.

If you want a more established Java web framework, you could try Spark. If you want a more established Kotlin web framework, you can try the Spark Kotlin Wrapper.

Fluent and readable API

All the methods on the Javalin instance return this, making the API fully fluent. This will let you create a declarative and predictive REST API, that will be very easy to reason about for new developers joining your project. Javalin is at its best when you declare the application config and the REST API together:

Javalin app = Javalin.create()

app.routes(() -> {
    path("users", () -> {
        path(":user-id", () -> {
val app = Javalin.create().apply {

app.routes {
    path("users") {
        path(":user-id") {

Works well with both Java and Kotlin

The name Javalin comes from Java and Kotlin, and is meant to be used with both Java and Kotlin. The library itself is written primarily in Kotlin, but has a few core classes written in Java to achieve the best interoperability between the two languages. Javalin is intended as a “foot in the door” to Kotlin development for companies that already write a lot of Java, and anyone can easily set up a microservice REST API in Kotlin and try it out.
Go through the Kotlin REST API tutorial to see how to setup Kotlin with Maven, and how to use it with Javalin.

Embedded Web-server

Javalin runs on a fully configurable embedded web-server (jetty). This means that you can write your entire application in Javalin, and deploy it as a fat jar.
Pull requests for other embedded servers would be welcome (netty, undertow, etc).

  • Maven
  • Gradle
  • SBT
  • Grape
  • Leiningen
  • Buildr
  • Ivy

Not familiar with Maven? Click here for more detailed instructions.

compile 'io.javalin:javalin:1.3.0'

Not familiar with Gradle? Click here for more detailed instructions.

libraryDependencies += "io.javalin" % "javalin" % "1.3.0"
@Grab(group='io.javalin', module='javalin', version='1.3.0') 
[io.javalin/javalin "1.3.0"]
<dependency org="io.javalin" name="javalin" rev="1.3.0" />

Like Javalin?