Module io.avaje.jex
Package io.avaje.jex

Interface Jex


public sealed interface Jex
Create configure and start Jex.

 final Jex.Server app = Jex.create()
   .routing(routing -> routing
     .get("/", ctx -> ctx.text("hello world"))
     .get("/one", ctx -> ctx.text("one"))
   .port(8080)
   .start();

 app.shutdown();

 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    The running server.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    attribute(Class<T> cls)
    Returns a custom attribute previously set using attribute(Class, Object).
    <T> Jex
    attribute(Class<T> cls, T instance)
    Sets a custom attribute that can be accessed later by the Jex instance or its components.
    Return the configuration.
    Configures the Jex instance using a functional approach.
    configureWith(io.avaje.inject.BeanScope beanScope)
    Configures the Jex instance using a dependency injection scope from Avaje-Inject.
    context(String contextPath)
    Sets the context path for the Jex application.
    static Jex
    Create Jex.
    jsonService(JsonService jsonService)
    Sets the JSON service to use for serialization and deserialization.
    Return the application lifecycle support.
    plugin(JexPlugin plugin)
    Adds a plugin to the Jex instance, extending its functionality.
    port(int port)
    Sets the port number on which the Jex server will listen for incoming requests.
    register(TemplateRender renderer, String... extensions)
    Explicitly register a template renderer.
    Returns the routing configuration object, allowing for further customization.
    Adds a new HTTP route and its associated handler to the Jex routing configuration.
    Adds multiple HTTP routes and their associated handlers to the Jex routing configuration.
    Start the server.
  • Method Details

    • create

      static Jex create()
      Create Jex.
      
       final Jex.Server app = Jex.create()
         .routing(routing -> routing
           .get("/", ctx -> ctx.text("hello world"))
           .get("/one", ctx -> ctx.text("one"))
         .port(8080)
         .start();
      
       app.shutdown();
      
       
    • attribute

      <T> Jex attribute(Class<T> cls, T instance)
      Sets a custom attribute that can be accessed later by the Jex instance or its components.
      Type Parameters:
      T - The type of the attribute.
      Parameters:
      cls - The class of the attribute.
      instance - The instance of the attribute.
    • attribute

      <T> T attribute(Class<T> cls)
      Returns a custom attribute previously set using attribute(Class, Object).
      Type Parameters:
      T - The type of the attribute.
      Parameters:
      cls - The class of the attribute.
      Returns:
      The attribute instance, or null if not found.
    • routing

      Jex routing(Routing.HttpService routes)
      Adds a new HTTP route and its associated handler to the Jex routing configuration.
      Parameters:
      routes - The HTTP service to add.
    • routing

      Adds multiple HTTP routes and their associated handlers to the Jex routing configuration.
      Parameters:
      routes - A collection of HTTP services to add.
    • routing

      Routing routing()
      Returns the routing configuration object, allowing for further customization.
      Returns:
      The routing configuration object.
    • jsonService

      Jex jsonService(JsonService jsonService)
      Sets the JSON service to use for serialization and deserialization.
      Parameters:
      jsonService - The JSON service to use.
    • plugin

      Jex plugin(JexPlugin plugin)
      Adds a plugin to the Jex instance, extending its functionality.
      Parameters:
      plugin - The plugin to add.
    • configureWith

      Jex configureWith(io.avaje.inject.BeanScope beanScope)
      Configures the Jex instance using a dependency injection scope from Avaje-Inject.

      This method allows you to leverage the Avaje-Inject framework to provide dependencies like Handlers, StaticResources, and Plugins to the Jex instance.

      Parameters:
      beanScope - The Avaje-Inject BeanScope containing the dependencies.
      Returns:
      The configured Jex instance.
    • configure

      Jex configure(Consumer<JexConfig> configure)
      Configures the Jex instance using a functional approach.

      The provided consumer lambda allows you to customize the Jex configuration, such as setting the port, compression, and other options.

      Parameters:
      configure - A consumer lambda that accepts a JexConfig instance for configuration.
      Returns:
      The configured Jex instance.
    • port

      Jex port(int port)
      Sets the port number on which the Jex server will listen for incoming requests.
      Parameters:
      port - The port number to use.
    • context

      Jex context(String contextPath)
      Sets the context path for the Jex application.

      The context path is the portion of the URL that identifies the application.

      Parameters:
      contextPath - The context path to use.
      Returns:
      The updated Jex instance.
    • register

      Jex register(TemplateRender renderer, String... extensions)
      Explicitly register a template renderer.

      Note that if not explicitly registered TemplateRender's can be automatically registered via ServiceLoader just by including them to the class path.

      Parameters:
      renderer - The template renderer to register
      extensions - The extensions the renderer is used for
    • lifecycle

      AppLifecycle lifecycle()
      Return the application lifecycle support.
    • config

      JexConfig config()
      Return the configuration.
    • start

      Jex.Server start()
      Start the server.