Class Javalin
-
- All Implemented Interfaces:
-
io.javalin.router.JavalinDefaultRoutingApi
,io.javalin.router.RoutingApi
public class Javalin implements JavalinDefaultRoutingApi<API>
-
-
Method Summary
Modifier and Type Method Description JavalinConfig
unsafeConfig()
JettyServer
jettyServer()
static Javalin
create()
Creates a new instance without any custom configuration. static Javalin
create(Consumer<JavalinConfig> config)
Creates a new instance with the user provided configuration. static Javalin
createAndStart(Consumer<JavalinConfig> config)
Creates a new instance with the user provided configuration and starts it immediately. Servlet
javalinServlet()
Javalin
start(String host, int port)
Synchronously starts the application instance on the specified port with the given host IP to bind to. Javalin
start(int port)
Synchronously starts the application instance on the specified port. Javalin
start()
Synchronously starts the application instance on the configured port, or on the configured ServerConnectors if the Jetty server has been manually configured. Javalin
stop()
Synchronously stops the application instance. Javalin
events(Consumer<EventConfig> listener)
int
port()
Get which port instance is running on Mostly useful if you start the instance with port(0) (random port) <E extends Exception> Javalin
exception(@NotNull() Class<E> exceptionClass, @NotNull() ExceptionHandler<in E> exceptionHandler)
Adds an exception mapper to the instance. Javalin
error(int status, @NotNull() String contentType, @NotNull() Handler handler)
Adds an error mapper for the specified content-type to the instance. Javalin
addEndpoint(@NotNull() Endpoint endpoint)
Adds a request handler for the specified handlerType and path to the instance. <E extends Exception> Javalin
wsException(@NotNull() Class<E> exceptionClass, @NotNull() WsExceptionHandler<in E> exceptionHandler)
Adds a WebSocket exception mapper to the instance. Javalin
addWsHandler(@NotNull() WsHandlerType handlerType, @NotNull() String path, @NotNull() Consumer<WsConfig> wsConfig, @NotNull() Array<RouteRole> roles)
Adds a WebSocket handler of the specified type on the specified path. -
Methods inherited from class io.javalin.router.JavalinDefaultRoutingApi
addHttpHandler, after, afterMatched, before, beforeMatched, delete, error, get, head, options, patch, post, put, sse, ws, wsAfter, wsAfterUpgrade, wsBefore, wsBeforeUpgrade
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
unsafeConfig
@NotNull() JavalinConfig unsafeConfig()
-
jettyServer
JettyServer jettyServer()
-
create
static Javalin create()
Creates a new instance without any custom configuration. The server does not run until start is called.
- Returns:
application instance
-
create
static Javalin create(Consumer<JavalinConfig> config)
Creates a new instance with the user provided configuration. The server does not run until start is called.
- Returns:
application instance
-
createAndStart
static Javalin createAndStart(Consumer<JavalinConfig> config)
Creates a new instance with the user provided configuration and starts it immediately.
- Returns:
running application instance
-
javalinServlet
Servlet javalinServlet()
-
start
Javalin start(String host, int port)
Synchronously starts the application instance on the specified port with the given host IP to bind to.
- Parameters:
host
- The host IP to bind toport
- to run on- Returns:
running application instance.
-
start
Javalin start(int port)
Synchronously starts the application instance on the specified port. Use port 0 to start the application instance on a random available port.
- Parameters:
port
- to run on- Returns:
running application instance.
-
start
Javalin start()
Synchronously starts the application instance on the configured port, or on the configured ServerConnectors if the Jetty server has been manually configured. If no port or connector is configured, the instance will start on port 8080.
- Returns:
running application instance.
-
stop
Javalin stop()
Synchronously stops the application instance.
- Returns:
stopped application instance.
-
events
Javalin events(Consumer<EventConfig> listener)
-
port
int port()
Get which port instance is running on Mostly useful if you start the instance with port(0) (random port)
-
exception
@NotNull() <E extends Exception> Javalin exception(@NotNull() Class<E> exceptionClass, @NotNull() ExceptionHandler<in E> exceptionHandler)
Adds an exception mapper to the instance. See: Exception mapping in docs
-
error
@NotNull() Javalin error(int status, @NotNull() String contentType, @NotNull() Handler handler)
Adds an error mapper for the specified content-type to the instance. Useful for turning error-codes (404, 500) into standardized messages/pages See: Error mapping in docs
-
addEndpoint
@NotNull() Javalin addEndpoint(@NotNull() Endpoint endpoint)
Adds a request handler for the specified handlerType and path to the instance. This is the method that all the verb-methods (get/post/put/etc) call. See: Handlers in docs
-
wsException
@NotNull() <E extends Exception> Javalin wsException(@NotNull() Class<E> exceptionClass, @NotNull() WsExceptionHandler<in E> exceptionHandler)
Adds a WebSocket exception mapper to the instance. See: Exception mapping in docs
-
addWsHandler
@NotNull() Javalin addWsHandler(@NotNull() WsHandlerType handlerType, @NotNull() String path, @NotNull() Consumer<WsConfig> wsConfig, @NotNull() Array<RouteRole> roles)
Adds a WebSocket handler of the specified type on the specified path. See: WebSockets in docs
-
-
-
-