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();

 
  • 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();
      
       
    • 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.
    • get

      default Jex get(String path, ExchangeHandler handler, Role... roles)
      Adds a GET handler to the route configuration.
      Parameters:
      path - The path pattern to match the request URI.
      handler - The handler to invoke when a GET request matches the path.
      roles - An array of roles that are associated with this endpoint.
    • post

      default Jex post(String path, ExchangeHandler handler, Role... roles)
      Adds a POST handler to the route configuration.
      Parameters:
      path - The path pattern to match the request URI.
      handler - The handler to invoke when a POST request matches the path.
      roles - An array of roles that are associated with this endpoint.
    • put

      default Jex put(String path, ExchangeHandler handler, Role... roles)
      Adds a PUT handler to the route configuration.
      Parameters:
      path - The path pattern to match the request URI.
      handler - The handler to invoke when a PUT request matches the path.
      roles - An array of roles that are associated with this endpoint.
    • patch

      default Jex patch(String path, ExchangeHandler handler, Role... roles)
      Adds a PATCH handler to the route configuration.
      Parameters:
      path - The path pattern to match the request URI.
      handler - The handler to invoke when a PATCH request matches the path.
      roles - An array of roles that are associated with this endpoint.
    • delete

      default Jex delete(String path, ExchangeHandler handler, Role... roles)
      Adds a DELETE handler to the route configuration.
      Parameters:
      path - The path pattern to match the request URI.
      handler - The handler to invoke when a DELETE request matches the path.
      roles - An array of roles that are associated with this endpoint.
    • options

      default Jex options(String path, ExchangeHandler handler, Role... roles)
      Adds an OPTIONS handler to the route configuration.
      Parameters:
      path - The path pattern to match the request URI.
      handler - The handler to invoke when an OPTIONS request matches the path.
      roles - An array of roles that are associated with this endpoint.
    • filter

      default Jex filter(HttpFilter handler)
      Add a filter for all matched requests.
    • before

      default Jex before(Consumer<Context> handler)
      Add a pre-processing filter for all matched requests.
    • after

      default Jex after(Consumer<Context> handler)
      Add a post-processing filter for all matched requests.
    • error

      default <T extends Exception> Jex error(Class<T> exceptionClass, ExceptionHandler<T> handler)
      Registers an exception handler that handles the given type of exceptions. This will replace an existing error handler for the same exception class.
      Type Parameters:
      T - exception type
      Parameters:
      exceptionClass - the type of exception to handle by this handler
      handler - the error handler
    • group

      default Jex group(String path, Routing.HttpService group)
      Add a group of route handlers with a common path prefix.
      
       routing.path("api", g -> {
           g.get("/", ctx -> ctx.text("apiRoot"));
           g.get("{id}", ctx -> ctx.text("api-" + ctx.pathParam("id")));
       });
      
       
      Parameters:
      path - the common path prefix
      group - the function to register the rout handlers
    • 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.
    • config

      Jex config(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.

      The default value is 8080. If The port is set to 0, the server will randomly choose an available port.

      Parameters:
      port - The port number to use.
    • contextPath

      Jex contextPath(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.