Package 

Class Javalin

    • Method Detail

      • create

         static Javalin create()

        Creates a new instance without any custom configuration.

      • 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 to
        port - to run on
      • 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
      • 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.

      • stop

         Javalin stop()

        Synchronously stops the application instance. Recommended to use close instead with Java's try-with-resources or Kotlin's use. This differs from close by firing lifecycle events even if the server is stopping or already stopped. This could cause your listeners to observe nonsensical state transitions. E.g. started -> stopping -> stopped -> stopping -> stopped.

      • close

         void close()

        Synchronously stops the application instance. Can safely be called multiple times.

      • port

         int port()

        Get which port instance is running on Mostly useful if you start the instance with port(0) (random port)

      • attribute

         Javalin attribute(String key, Object value)

        Registers an attribute on the instance. Instance is available on the Context through appAttribute. Ex: app.attribute(MyExt.class, myExtInstance()) The method must be called before start.

      • attribute

         <T> T attribute(String key)

        Retrieve an attribute stored on the instance. Available on the Context through appAttribute. Ex: app.attribute(MyExt.class).myMethod() Ex: ctx.appAttribute(MyExt.class).myMethod()

      • routes

         Javalin routes(@NotNull() EndpointGroup endpointGroup)

        Creates a temporary static instance in the scope of the endpointGroup. Allows you to call get(handler), post(handler), etc. without without using the instance prefix.

      • error

         Javalin error(HttpStatus status, @NotNull() Handler handler)

        Adds an error mapper to the instance. Useful for turning error-codes (404, 500) into standardized messages/pages

      • error

         Javalin error(int status, @NotNull() Handler handler)

        Adds an error mapper to the instance. Useful for turning error-codes (404, 500) into standardized messages/pages

      • error

         Javalin error(HttpStatus 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

      • error

         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

      • addHandler

         Javalin addHandler(@NotNull() HandlerType handlerType, @NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a request handler for the specified handlerType and path to the instance. Requires an access manager to be set on the instance. This is the method that all the verb-methods (get/post/put/etc) call.

      • addHandler

         Javalin addHandler(@NotNull() HandlerType httpMethod, @NotNull() String path, @NotNull() Handler handler)

        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.

      • get

         Javalin get(@NotNull() String path, @NotNull() Handler handler)

        Adds a GET request handler for the specified path to the instance.

      • post

         Javalin post(@NotNull() String path, @NotNull() Handler handler)

        Adds a POST request handler for the specified path to the instance.

      • put

         Javalin put(@NotNull() String path, @NotNull() Handler handler)

        Adds a PUT request handler for the specified path to the instance.

      • patch

         Javalin patch(@NotNull() String path, @NotNull() Handler handler)

        Adds a PATCH request handler for the specified path to the instance.

      • delete

         Javalin delete(@NotNull() String path, @NotNull() Handler handler)

        Adds a DELETE request handler for the specified path to the instance.

      • head

         Javalin head(@NotNull() String path, @NotNull() Handler handler)

        Adds a HEAD request handler for the specified path to the instance.

      • options

         Javalin options(@NotNull() String path, @NotNull() Handler handler)

        Adds a OPTIONS request handler for the specified path to the instance.

      • get

         Javalin get(@NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a GET request handler with the given roles for the specified path to the instance. Requires an access manager to be set on the instance.

      • post

         Javalin post(@NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a POST request handler with the given roles for the specified path to the instance. Requires an access manager to be set on the instance.

      • put

         Javalin put(@NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a PUT request handler with the given roles for the specified path to the instance. Requires an access manager to be set on the instance.

      • patch

         Javalin patch(@NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a PATCH request handler with the given roles for the specified path to the instance. Requires an access manager to be set on the instance.

      • delete

         Javalin delete(@NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a DELETE request handler with the given roles for the specified path to the instance. Requires an access manager to be set on the instance.

      • head

         Javalin head(@NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a HEAD request handler with the given roles for the specified path to the instance. Requires an access manager to be set on the instance.

      • options

         Javalin options(@NotNull() String path, @NotNull() Handler handler, @NotNull() Array<RouteRole> roles)

        Adds a OPTIONS request handler with the given roles for the specified path to the instance. Requires an access manager to be set on the instance.

      • sse

         Javalin sse(@NotNull() String path, @NotNull() SseHandler handler)

        Adds a lambda handler for a Server Sent Event connection on the specified path.

      • sse

         Javalin sse(@NotNull() String path, @NotNull() Consumer<SseClient> client, @NotNull() Array<RouteRole> roles)

        Adds a lambda handler for a Server Sent Event connection on the specified path. Requires an access manager to be set on the instance.

      • before

         Javalin before(@NotNull() String path, @NotNull() Handler handler)

        Adds a BEFORE request handler for the specified path to the instance.

      • before

         Javalin before(@NotNull() Handler handler)

        Adds a BEFORE request handler for all routes in the instance.

      • after

         Javalin after(@NotNull() String path, @NotNull() Handler handler)

        Adds an AFTER request handler for the specified path to the instance.

      • after

         Javalin after(@NotNull() Handler handler)

        Adds an AFTER request handler for all routes in the instance.

      • ws

         Javalin ws(@NotNull() String path, @NotNull() Consumer<WsConfig> ws, @NotNull() Array<RouteRole> roles)

        Adds a WebSocket handler on the specified path with the specified roles. Requires an access manager to be set on the instance.