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 -
Method Summary
Modifier and TypeMethodDescription<T> TReturns a custom attribute previously set usingattribute(Class, Object).<T> JexSets a custom attribute that can be accessed later by the Jex instance or its components.config()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.Sets the context path for the Jex application.static Jexcreate()Create Jex.jsonService(JsonService jsonService) Sets the JSON service to use for serialization and deserialization.Return the application lifecycle support.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.routing()Returns the routing configuration object, allowing for further customization.routing(Routing.HttpService routes) Adds a new HTTP route and its associated handler to the Jex routing configuration.routing(Collection<Routing.HttpService> routes) Adds multiple HTTP routes and their associated handlers to the Jex routing configuration.start()Start the server.default JexstaticResource(StaticContentConfig config) Adds a static resource route using the provided configuration.default JexstaticResource(Consumer<StaticContentConfig> consumer) Adds a static resource route using a consumer to configure theStaticContentConfig.
-
Method Details
-
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
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
Returns a custom attribute previously set usingattribute(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
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.
-
staticResource
Adds a static resource route using the provided configuration.- Parameters:
config- The configuration for the static resource route.
-
staticResource
Adds a static resource route using a consumer to configure theStaticContentConfig.- Parameters:
consumer- The consumer to configure the static resource route.
-
jsonService
Sets the JSON service to use for serialization and deserialization.- Parameters:
jsonService- The JSON service to use.
-
plugin
Adds a plugin to the Jex instance, extending its functionality.- Parameters:
plugin- The plugin to add.
-
configureWith
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
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 aJexConfiginstance for configuration.- Returns:
- The configured Jex instance.
-
port
Sets the port number on which the Jex server will listen for incoming requests.- Parameters:
port- The port number to use.
-
context
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
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 registerextensions- 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.
-