Javalin: The Lightweight Java Web Framework Tutorial
Javalin is a lightweight web framework for Java and Kotlin. If big frameworks feel like overkill, Javalin is refreshing: you can build a working REST API in just a few lines, with no XML and almost no configuration. This beginner tutorial explains what Javalin is, when to use it, and how to write your first endpoint. It's one of the simplest Java web frameworks to learn.
What is Javalin?
Javalin is an open-source, lightweight ("micro") web framework. The whole philosophy is simplicity: a small, readable set of tools for handling web requests, and nothing you don't need. It runs on the embedded Jetty web server, so like Spring Boot your app runs as a single program — no separate server to set up.
"Lightweight" here means two things: a small amount of code for you to write, and a small footprint when it runs. That's the opposite trade-off from a feature-packed framework like Spring Boot.
Why choose a lightweight framework?
Not every project needs a giant framework. If you're building a small REST API, a quick prototype, or you're just learning how web servers work, a lightweight framework gets you there faster and with less to understand. Benefits:
- Tiny learning curve — the whole API fits in your head.
- Fast startup — less to load means quicker boot.
- Readable code — your routes are right there, easy to follow.
- Great for learning — you see exactly what's happening with each request.
Your first Javalin app
This is a complete, runnable Javalin web server. That's not a snippet — that's the whole thing:
import io.javalin.Javalin;
public class Main {
public static void main(String[] args) {
Javalin app = Javalin.create().start(7070);
app.get("/hello", ctx -> ctx.result("Hello from Javalin!"));
}
}
Run it, visit http://localhost:7070/hello, and you'll see your message. The ctx (context)
object holds everything about the request and lets you build the response. Returning JSON is just as easy:
app.get("/user", ctx -> ctx.json(new User("Ada", 36))); When should you use Javalin?
Reach for Javalin when:
- You're building a small or medium REST API.
- You want to learn web development without framework overload.
- You're writing a quick prototype and want to move fast.
- You work in Kotlin and want a framework that feels native.
For large enterprise systems with complex security, data access, and integrations, a fuller framework like Spring Boot is usually a better fit. See more options in our guide to lightweight Java frameworks.
Quick recap
- Javalin is a lightweight web framework for Java and Kotlin.
- You can build a working REST API in just a few lines of code.
- It runs on embedded Jetty, so your app is a single runnable program.
- Best for small APIs, prototypes, and learning — not heavyweight enterprise apps.