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 TypeMethodDescriptiondefault JexAdd a post-processing filter for all matched requests.default JexAdd a pre-processing filter for all matched requests.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.contextPath(String contextPath) Sets the context path for the Jex application.static Jexcreate()Create Jex.default Jexdelete(String path, ExchangeHandler handler, Role... roles) Adds a DELETE handler to the route configuration.error(Class<T> exceptionClass, ExceptionHandler<T> handler) Registers an exception handler that handles the given type of exceptions.default Jexfilter(HttpFilter handler) Add a filter for all matched requests.default Jexget(String path, ExchangeHandler handler, Role... roles) Adds a GET handler to the route configuration.default Jexgroup(String path, Routing.HttpService group) Add a group of route handlers with a common path prefix.jsonService(JsonService jsonService) Sets the JSON service to use for serialization and deserialization.Return the application lifecycle support.default Jexoptions(String path, ExchangeHandler handler, Role... roles) Adds an OPTIONS handler to the route configuration.default Jexpatch(String path, ExchangeHandler handler, Role... roles) Adds a PATCH handler to the route configuration.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.default Jexpost(String path, ExchangeHandler handler, Role... roles) Adds a POST handler to the route configuration.default Jexput(String path, ExchangeHandler handler, Role... roles) Adds a PUT handler to the route configuration.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.
-
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(); -
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.
-
get
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
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
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
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
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
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
Add a filter for all matched requests. -
before
Add a pre-processing filter for all matched requests. -
after
Add a post-processing filter for all matched requests. -
error
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 handlerhandler- the error handler
-
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 prefixgroup- the function to register the rout handlers
-
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.
-
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
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.
-