Questions tagged [javalin]

Use this tag for programming questions about the Javalin web framework for Java and Kotlin.

Overview

Javalin is a lightweight web framework built on the Jetty web server.

The framework can be integrated into Java and Kotlin projects.

Javalin supports several template engines including Thymeleaf and Velocity. It has built-in support for WebSockets, HTTP2, static file serving, exception mapping, server-sent events, asynchronous mode, as well as a variety of common tasks such as validation, access control, logging, and server configuration.

An OpenAPI (Swagger) plugin is also provided, as well as a GraphQL plugin.


Resources


Hello World

Java:

import io.javalin.Javalin;

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

Kotlin:

import io.javalin.Javalin

fun main() {
    val app = Javalin.create().start(7070)
    app.get("/") { ctx -> ctx.result("Hello World") }
}
86 questions
7
votes
2 answers

Isolate the instantiation of an annotation

I have a huge @OpenApi annotation (basically it's documentation of a Javalin/Kotlin endpoint) which occupies a lot of lines: @OpenApi( summary = "", description = "Lists all customers", path = "customers", queryParams = //…
Luís Soares
  • 5,726
  • 4
  • 39
  • 66
5
votes
2 answers

How to get Javalin's Jetty http server to bind/listen on a specific address/port?

Using Javalin.create().port(portNumber) sets the listen port, but it's unclear how to set the listen/bind address.
karmakaze
  • 34,689
  • 1
  • 30
  • 32
4
votes
0 answers

Javalin/Kotlin OpenAPI error: SwaggerUIBundle is not defined

Is there anything I am missing? Had the code that worked locally, when deployed I get ReferenceError: SwaggerUIBundle is not defined After I cleared my browsing data I get the same error locally as well. Below are the…
Bizgu Daniela
  • 61
  • 1
  • 7
3
votes
1 answer

Java application runs much slower when packaged as a MacOs app

I've written a Java application that I want to package for the main OSes so that I can provide it as a self-contained installable image. To do this, I use jpackage, with help from the best-named plugin I've come across, The Badass Runtime Plugin…
AndyW
  • 101
  • 7
3
votes
1 answer

Why isn't Swagger detecting optional JSON properties?

I have the following class: import com.fasterxml.jackson.annotation.JsonProperty import org.joda.time.DateTime import org.joda.time.DateTimeZone data class Entity( val email: String, val name: String, val birthDate:…
3
votes
2 answers

Junit assertions don't work when called inside a Javalin handler

I have this test that launches a service at port 7000 and inside the only endpoint I do a failing assertion: @Test fun `javalin assertion should fail`() { Javalin.create() .get("/") { assertTrue(false) } .start() …
Luís Soares
  • 5,726
  • 4
  • 39
  • 66
3
votes
1 answer

How to disable Javalin logging

I'd like to turn off this logging under Javalin: [main] INFO org.eclipse.jetty.util.log - Logging initialized @850ms to org.eclipse.jetty.util.log.Slf4jLog [main] INFO io.javalin.Javalin - Starting Javalin ... [main] INFO io.javalin.Javalin -…
Luís Soares
  • 5,726
  • 4
  • 39
  • 66
3
votes
1 answer

How to make the client receive server sent event using Javalin?

I am trying to implement a server client project which needs the server to send data to the client every 5 minutes with the client only asking in the beginning of connection. Server-sent events seem to be the go-to solution. I have tried to use the…
Alp
  • 63
  • 6
2
votes
2 answers

Configure Javalin (Jetty) max request size (414 URI too long)

How do you configure Javalin to change the max request size, specifically the config to increase the max size of the query parameters on the request (avoiding 414 URI too long)? I get 414 URI is too long when I exceed what looks like a default size…
Toby
  • 9,523
  • 8
  • 36
  • 59
2
votes
1 answer

reuse the same set of routes in multiple paths with Javalin

so I am trying to refactor my route definitions in Javalin to be a little more DRY. So I have the same set of actions performed at different hierarchies. I have a company, an application, and a environment and for each of these, I've split into…
chrisaitk
  • 23
  • 4
2
votes
1 answer

How do you configure Javalin to render Pebble pages/templates?

I tried Search the documentation but I still don't understand. Here's my code to start up the app. public static void main(String[] args){ Javalin app = Javalin.create( config -> { …
Hiep Huynh
  • 21
  • 1
  • 2
2
votes
1 answer

Using JPA in a Javalin application

I am creating a web application in Java and would like to use the Javalin framework. Issues/questions: What would be the best way to use JPA (via hibernate) in a Javalin web application? I.e. what is the best way make a JPA EntityManager object…
codeape
  • 97,830
  • 24
  • 159
  • 188
2
votes
1 answer

Restricting options method in javalin

We have a kotlin code like the following, I am trying to disable the options method for the API's as follows using Javalin(3.12.0), but it is resulting in blocking all the other methods like get and post as well. What is that I am missing here? val…
Maverick
  • 397
  • 1
  • 4
  • 18
2
votes
1 answer

Javalin Migration from 3 to 4

We are migrating the Javalin from 3 to 4 in our current kotlin project. the dynamicGzip has been deprecated and replaced with compression strategy. The pom.xml part will look like below. 4.1.1
Maverick
  • 397
  • 1
  • 4
  • 18
2
votes
1 answer

How do you read multiple body parameters from Javalin?

I would like to access multiple body parameters of different types to use in my POST route in my API, but I don't know how to access the body parameters in Javalin. I haven't found any information concerning body parameters or best POST practices in…
mooglin
  • 500
  • 5
  • 17
1
2 3 4 5 6