### Install and Setup AWS Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/awssdkv2.adoc Install the AwsModule and use the setup function to configure AWS services like S3Client and S3TransferManager. Services are registered and shut down with the application. ```kt import io.jooby.awssdkv2.AwsModule import software.amazon.awssdk.services.s3.S3Client import software.amazon.awssdk.transfer.s3.S3TransferManager import java.util.stream.Stream { install( AwsModule() .setup { credentials -> val s3 = S3Client.builder().build() val s3transfer = S3TransferManager.builder().s3Client(s3).build() return Stream.of(s3, s3transfer) } ) ); } ``` -------------------------------- ### Install and Setup AWS Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/awssdkv2.adoc Install the AwsModule and use the setup function to configure AWS services like S3Client and S3TransferManager. Services are registered and shut down with the application. ```java import io.jooby.awssdkv2.AwsModule; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.transfer.s3.S3TransferManager; import java.util.stream.Stream; { install( new AwsModule() .setup(credentials -> { var s3 = S3Client.builder().build(); var s3transfer = S3TransferManager.builder().s3Client(s3).build(); return Stream.of(s3, s3transfer); }) ) ); } ``` -------------------------------- ### Install and Setup AWS Module in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/aws.adoc Installs the AwsModule and sets up the S3 client and TransferManager using provided credentials. Services are registered in the application service registry and shut down on application shutdown. ```java import io.jooby.awssdkv1.AwsModule; { install( new AwsModule() <1> .setup(credentials -> { <2> return TransferManagerBuilder.standard() .withS3Client( AmazonS3ClientBuilder.standard() .withRegion(Regions.US_EAST_1) .withCredentials(credentials) .build() <3> ).build(); <4> }) ); } ``` -------------------------------- ### GraphiQL 5 Setup with React 19 and Explorer Plugin Source: https://github.com/jooby-project/jooby/blob/main/modules/jooby-graphiql/src/main/resources/io/jooby/graphiql/index.html This example demonstrates the full setup for GraphiQL 5 using React 19 and the GraphiQL Explorer plugin. It includes necessary imports, fetcher configuration, and plugin integration for a complete GraphiQL interface. ```javascript body { margin: 0; } #graphiql { height: 100dvh; } .loading { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 4rem; } ``` ```json { "imports": { "react": "https://esm.sh/react@19.1.0", "react/": "https://esm.sh/react@19.1.0/", "react-dom": "https://esm.sh/react-dom@19.1.0", "react-dom/": "https://esm.sh/react-dom@19.1.0/", "graphiql": "https://esm.sh/graphiql?standalone&external=react,react-dom,@graphiql/react,graphql", "graphiql/": "https://esm.sh/graphiql/", "@graphiql/plugin-explorer": "https://esm.sh/@graphiql/plugin-explorer?standalone&external=react,@graphiql/react,graphql", "@graphiql/react": "https://esm.sh/@graphiql/react?standalone&external=react,react-dom,graphql,@graphiql/toolkit,@emotion/is-prop-valid", "@graphiql/toolkit": "https://esm.sh/@graphiql/toolkit?standalone&external=graphql", "graphql": "https://esm.sh/graphql@16.11.0", "@emotion/is-prop-valid": "data:text/javascript," } } ``` ```javascript import React from 'react'; import ReactDOM from 'react-dom/client'; import { GraphiQL, HISTORY_PLUGIN } from 'graphiql'; import { createGraphiQLFetcher } from '@graphiql/toolkit'; import { explorerPlugin } from '@graphiql/plugin-explorer'; import 'graphiql/setup-workers/esm.sh'; const fetcher = createGraphiQLFetcher({ url: 'https://countries.trevorblades.com', }); const plugins = [ HISTORY_PLUGIN, explorerPlugin(), ]; function App() { return React.createElement(GraphiQL, { fetcher, plugins, defaultEditorToolsVisibility: true, }); } const container = document.getElementById('graphiql'); const root = ReactDOM.createRoot(container); root.render(React.createElement(App)); ``` -------------------------------- ### Basic Pebble Setup in Jooby (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/pebble.adoc Install the PebbleModule and define a route that renders an index.peb template with a name variable. Assumes templates are in the 'views' folder. ```java import io.jooby.pebble.PebbleModule; { install(new PebbleModule()); get("/", ctx -> { return new MapModelAndView("index.peb") .put("name", "Jooby"); }); } ``` -------------------------------- ### Install and Setup AWS Module in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/aws.adoc Installs the AwsModule and sets up the S3 client and TransferManager using provided credentials. Services are registered in the application service registry and shut down on application shutdown. ```kt import io.jooby.aws.AwsModule { install( AwsModule() .setup { credentials -> TransferManagerBuilder.standard() .withS3Client( AmazonS3ClientBuilder.standard() .withRegion(Regions.US_EAST_1) .withCredentials(credentials) .build() ).build() }) ); } ``` -------------------------------- ### Basic Pebble Setup in Jooby (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/pebble.adoc Install the PebbleModule and define a route that renders an index.peb template with a name variable. Assumes templates are in the 'views' folder. ```kt import io.jooby.pebble.PebbleModule { install(PebbleModule()) get("/") { MapModelAndView("index.peb") .put("name", "Jooby") } } ``` -------------------------------- ### MVC API Example Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/mvc-api.adoc An example demonstrating how to define a controller with the @Path and @GET annotations and register it in the application. ```APIDOC ## MVC API Example ### Description This example shows a basic MVC controller setup using Java and Kotlin. It defines a controller class with a path and a GET method, and then registers the generated controller in the application. ### Java Example: ```java import io.jooby.annotation.*; @Path("/mvc") // Sets a base path pattern for the controller public class Controller { @GET // Defines an HTTP GET method public String sayHi() { return "Hello Mvc!"; } } public class App extends Jooby { { mvc(new Controller_()); // Registers the generated controller } public static void main(String[] args) { runApp(args, App::new); } } ``` ### Kotlin Example: ```kotlin import io.jooby.annotation.* import io.jooby.kt.runApp @Path("/mvc") // Sets a base path pattern for the controller class Controller { @GET // Defines an HTTP GET method fun sayHi(): String { return "Hello Mvc!" } } fun main(args: Array) { runApp(args) { mvc(Controller_()) // Registers the generated controller } } ``` ``` -------------------------------- ### Install Standalone Application using `install` (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/routing.adoc Install a standalone application into another one using the `install` operator, which imports routes, services, and callbacks. ```java public class Foo extends Jooby { { get("/foo", ctx -> ...); } } public class Bar extends Jooby { { get("/bar", ctx -> ...); } } public class App extends Jooby { { install(Foo::new); install(Bar::new); } } ``` -------------------------------- ### Install Standalone Application using `install` (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/routing.adoc Install a standalone application into another one using the `install` operator, which imports routes, services, and callbacks. ```kotlin class Foo: Kooby({ get("/foo") { ... } }) class Bar: Kooby({ get("/bar") { ... } }) class App: Kooby({ install(::Foo) install(::Bar) }) ``` -------------------------------- ### Install Vertx SQL Client and Execute Query (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/templates/vertx-sql-connection.adoc Demonstrates how to install the Vertx SQL client module and execute a database query using prepared statements. Ensure the Vertx server and handler are also installed. ```java import io.jooby.vertx.VertxServer; import io.jooby.vertx.{{moduleName}}; import static io.jooby.vertx.VertxHandler.vertx; { install(new {{moduleName}}()); <2> use(vertx()); <3> get("/{id}", ctx -> { var db = require(SqlClient.class); <4> return db.preparedQuery("SELECT id, name from World where id=$1") <5> .execute(Tuple.of(ctx.path("id").longValue())) .map(result -> { var row = result.iterator().next(); return new World(row.getInteger(0), row.getInteger(1)); <6> }); }); } public static void main(String[] args) { runApp(args, new VertxServer(), EVENT_LOOP, MyApp::new); <1> } ``` -------------------------------- ### Install OpenTelemetry Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/opentelemetry.adoc Installs the core OpenTelemetry SDK engine. This must be installed at the very beginning of your application setup. ```kt import io.jooby.opentelemetry.OtelModule import io.jooby.opentelemetry.OtelHttpTracing { install(OtelModule()) use(OtelHttpTracing()) get("/") { ctx -> "Hello OTel" } } ``` -------------------------------- ### Basic Kotlin Application Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/index.adoc A simple 'Hello World' example for a Jooby application written in Kotlin. It defines a single GET route. ```kotlin import io.jooby.kt.runApp fun main(args: Array) { runApp(args) { get("/") { "Welcome to Jooby!" } } } ``` -------------------------------- ### Basic Java Application Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/index.adoc A simple 'Hello World' example for a Jooby application written in Java. It defines a single GET route. ```java import io.jooby.Jooby; public class App extends Jooby { { get("/", ctx -> "Welcome to Jooby!"); } public static void main(String[] args) { runApp(args, App::new); } } ``` -------------------------------- ### Install Quartz Module with SampleJob Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/quartz.adoc Installs the Quartz module and registers a SampleJob class. Use this when you have a specific job class to manage. ```java import io.jooby.quartz.QuartzModule; { install(new QuartzModule(SampleJob.class)); } ``` ```kt import io.jooby.quartz.QuartzModule { install(QuartzModule(SampleJob::class.java)) } ``` -------------------------------- ### Install OpenTelemetry Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/opentelemetry.adoc Installs the core OpenTelemetry SDK engine. This must be installed at the very beginning of your application setup. ```java import io.jooby.opentelemetry.OtelModule; import io.jooby.opentelemetry.OtelHttpTracing; { install(new OtelModule()); use(new OtelHttpTracing()); get("/", ctx -> { return "Hello OTel"; }); } ``` -------------------------------- ### Install Avaje-JsonB Module Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/avaje-jsonb.adoc Install the AvajeJsonbModule to enable JSON support. This is typically done during application setup. ```java import io.jooby.avaje.jsonb.AvajeJsonbModule; { install(new AvajeJsonbModule()); <1> get("/", ctx -> { MyObject myObject = ...; return myObject; <2> }); post("/", ctx -> { MyObject myObject = ctx.body(MyObject.class); <3> ... }); } ``` ```kt import io.jooby.avaje.jsonb.AvajeJsonbModule { install(AvajeJsonbModule()) <1> get("/") { val myObject = ...; myObject <2> } post("/") { val myObject = ctx.body() <3> ... } } ``` -------------------------------- ### Install HeadHandler in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/handlers/head.adoc Install the HeadHandler to automatically route HEAD requests to GET handlers. The GET handler logic still runs, so consider custom implementations for expensive body generation. ```java import io.jooby.handler.HeadHandler; { use(new HeadHandler()); // <1> get("/", ctx -> "Full response body"); } ``` -------------------------------- ### Install Quartz Module with a Job Class Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/quartz.adoc Installs the Quartz module and registers a specific job class. Ensure necessary modules like Hikari are installed first. ```kotlin import io.jooby.quartz.QuartzModule { install(new HikariModule()) install(QuartzModule(SampleJob::class.java)) } ``` -------------------------------- ### Install default VertxModule in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/vertx.adoc Install the VertxModule with default configuration. ```java import io.jooby.vertx.VertxModule; { install(new VertxModule()); } ``` -------------------------------- ### Install OpenAPIModule in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/openapi.adoc Install the OpenAPIModule in Kotlin for API documentation generation. This is part of the application's setup. ```kt install(OpenAPIModule()) <1> path("/pets") { get("/") { val repo = ...; repo.list() } } ``` -------------------------------- ### Install and Use Ebean (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/ebean.adoc Install HikariCP and Ebean modules, then obtain and use the Ebean Database instance. ```kt import io.jooby.hikari.HikariModule import io.jooby.ebean.EbeanModule { install(HikariModule()) install(EbeanModule()) get("/") { val db = require(Database::class) <3> // work with Database } } ``` -------------------------------- ### Install GraphQL Playground Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/graphql.adoc Install the GraphQL Playground module for an advanced in-browser IDE. This requires Jackson and GraphQL modules to be installed first. ```java import io.jooby.json.Jackson2Module; import io.jooby.graphql.GraphQLModule; import io.jooby.graphql.GraphQLPlaygroundModule; { install(new Jackson2Module()); <1> install(new GraphQLModule(...)); <2> install(new GraphQLPlaygroundModule()); <3> } ``` -------------------------------- ### Populate Schema with Example Data Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/openapi-ascii.adoc Use the `example` mutator to populate a Schema or Body definition with example data. ```twig | example ``` -------------------------------- ### Enable HTTP/2 and Install gRPC Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/gRPC.adoc Enable HTTP/2 on your server and install the gRPC module, registering your services. ```kotlin import io.jooby.ServerOptions import io.jooby.grpc.GrpcModule import io.jooby.kt.Kooby { serverOptions = ServerOptions().setHttp2(true) // <1> install(GrpcModule(GreeterService())) // <2> } ``` -------------------------------- ### Install Freemarker Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/freemarker.adoc Install the Freemarker module and define a route that renders an index template with a name variable. ```kt import io.jooby.freemarker.FreemarkerModule { install(FreemarkerModule()) get("/") { MapModelAndView("index.ftl") .put("name", "Jooby") } } ``` -------------------------------- ### Simple Pipeline Example Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/openapi-ascii.adoc A basic pipeline example demonstrating the direct flow from a data source to its display. ```twig {{ info.description }} ``` -------------------------------- ### Install GraphQL Playground Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/graphql.adoc Install the GraphQL Playground module for an advanced in-browser IDE. This requires Jackson and GraphQL modules to be installed first. ```kotlin import io.jooby.json.Jackson2Module import io.jooby.graphql.GraphQLModule import io.jooby.graphql.GraphQLPlaygroundModule { install(Jackson2Module()) <1> install(GraphQLModule(...)) <2> install(GraphQLPlaygroundModule()) <3> } ``` -------------------------------- ### Basic MVC Controller and Application Setup (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/mvc-api.adoc Defines a simple MVC controller with a GET route in Kotlin and registers it in the Jooby application. The controller class is suffixed with an underscore by default. ```kotlin import io.jooby.annotation.* import io.jooby.kt.runApp @Path("/mvc") // <1> class Controller { @GET // <2> fun sayHi(): String { return "Hello Mvc!" } } fun main(args: Array) { runApp(args) { mvc(Controller_()) // <3> } } ``` -------------------------------- ### Install and Use Ebean (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/ebean.adoc Install HikariCP and Ebean modules, then obtain and use the Ebean Database instance. ```java import io.jooby.hikari.HikariModule; import io.jooby.ebean.EbeanModule; { install(new HikariModule()); <1> install(new EbeanModule()); <2> get("/", ctx -> { Database db = require(Database.class); <3> // work with Database }); } ``` -------------------------------- ### Enable HTTP/2 and Install gRPC Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/gRPC.adoc Enable HTTP/2 on your server and install the gRPC module, registering your services. ```java import io.jooby.Jooby; import io.jooby.ServerOptions; import io.jooby.grpc.GrpcModule; { setServerOptions(new ServerOptions().setHttp2(true)); // <1> install(new GrpcModule(new GreeterService())); // <2> } ``` -------------------------------- ### Install DbScheduler with SampleJob (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/db-scheduler.adoc Install the DbScheduler module, providing recurring tasks in Kotlin. ```kt import io.jooby.dbscheduler.DbSchedulerModule { install(DbSchedulerModule(Tasks.recurring(...))) } ``` -------------------------------- ### Install Node and NPM (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/node.adoc Install a specific version of Node and NPM using the NpmModule in Kotlin. This is typically done during application startup. ```kotlin import io.jooby.node.NpmModule { install(NpmModule("v12.16.1")) } ``` -------------------------------- ### Install Freemarker Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/freemarker.adoc Install the Freemarker module and define a route that renders an index template with a name variable. ```java import io.jooby.freemarker.FreemarkerModule; { install(new FreemarkerModule()); get("/", ctx -> { return new MapModelAndView("index.ftl") .put("name", "Jooby"); }); } ``` -------------------------------- ### Install GraphQL Playground Module Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/graphql.adoc Install the GraphQL Playground module to enable the GraphQL interface at the `/graphql` endpoint. This module is typically installed alongside the main GraphQL module. ```kotlin install(GraphQLPlaygroundModule()) ``` -------------------------------- ### Install GraphiQL Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/graphql.adoc Install the GraphiQL module to provide an in-browser IDE for interacting with your GraphQL API. Ensure Jackson and GraphQL modules are also installed. ```kotlin import io.jooby.json.Jackson2Module import io.jooby.graphql.GraphQLModule import io.jooby.graphql.GraphiQLModule { install(Jackson2Module()) <1> install(GraphQLModule(...)) <2> install(GraphiQLModule()) <3> } ``` -------------------------------- ### Install Pac4j Module Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/pac4j.adoc Installs the Pac4j module for basic authentication. Accesses the authenticated user profile via ctx.getUser(). ```java import io.jooby.pac4j.Pac4jModule; { install(new Pac4jModule()); get("/", ctx -> { UserProfile user = ctx.getUser(); return "Hello " + user.getId(); }); } ``` ```kt import io.jooby.pac4j.Pac4jModule { install(Pac4jModule()) get("/") { "Hello $ctx.user.id" } } ``` -------------------------------- ### Install Handlebars Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/handlebars.adoc Install the Handlebars module and define a route that renders an index.hbs template with a name variable. ```kt import io.jooby.handlebars.HandlebarsModule { install(HandlebarsModule()) get("/") { MapModelAndView("index.hbs") .put("name", "Jooby") } } ``` -------------------------------- ### Install Vertx SQL Client and Execute Query (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/templates/vertx-sql-connection.adoc Shows how to set up the Vertx SQL client and perform a database query with prepared statements in Kotlin. Includes installation of Vertx server and handler. ```kt import io.jooby.vertx.VertxServer import io.jooby.vertx.{{moduleName}} import static io.jooby.vertx.VertxHandler.vertx { install({{moduleName}}()); <2> use(vertx()) <3> get("/{id}") { val db = require(SqlClient::class) <4> db.preparedQuery("SELECT id, name from World where id=$1") <5> .execute(Tuple.of(ctx.path("id").longValue())) .map({ result -> val row = result.iterator().next() World(row.getInteger(0), row.getInteger(1)) <6> }) } } fun main(args: Array) { runApp(args, VertxServer(), EVENT_LOOP, ::MyApp) <1> } ``` -------------------------------- ### Install Node and NPM (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/node.adoc Install a specific version of Node and NPM using the NpmModule in Java. This is typically done during application startup. ```java import io.jooby.node.NpmModule; { install(new NpmModule("v12.16.1")); } ``` -------------------------------- ### Install GraphiQL Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/graphql.adoc Install the GraphiQL module to provide an in-browser IDE for interacting with your GraphQL API. Ensure Jackson and GraphQL modules are also installed. ```java import io.jooby.json.Jackson2Module; import io.jooby.graphql.GraphQLModule; import io.jooby.graphql.GraphiQLModule; { install(new Jackson2Module()); <1> install(new GraphQLModule(...)); <2> install(new GraphiQLModule()); <3> } ``` -------------------------------- ### Install OpenAPIModule in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/openapi.adoc Install the OpenAPIModule to enable API documentation generation. This is typically done during application bootstrap. ```java install(new OpenAPIModule()); <1> path("/pets", () { get("/", ctx -> { PetRepository repo = ...; return repo.list(); }); }); ``` -------------------------------- ### Install AccessLogHandler in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/handlers/access-log.adoc Install the AccessLogHandler as a global decorator in a Java application. ```java import io.jooby.handler.AccessLogHandler; { use(new AccessLogHandler()); // <1> get("/", ctx -> "Logging..."); } ``` -------------------------------- ### Install Jooby GrpcModule Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/gRPC.adoc Install the GrpcModule to enable gRPC services. ProtoReflectionServiceV1 is enabled for client compatibility. ```java import io.jooby.Jooby; import io.jooby.grpc.GrpcModule; { install(new GrpcModule( new GreeterService(), ProtoReflectionServiceV1.newInstance() // <1> )); } ``` ```kotlin import io.grpc.protobuf.services.ProtoReflectionServiceV1 import io.jooby.grpc.GrpcModule import io.jooby.kt.Kooby { install(GrpcModule( GreeterService(), ProtoReflectionServiceV1.newInstance() // <1> )) } ``` -------------------------------- ### Install HikariModule in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/hikari.adoc Install the HikariModule to enable the HikariCP connection pool. Requires the DataSource class to be available. ```java import io.jooby.hikari.HikariModule; { install(new HikariModule()); get("/", ctx -> { DataSource ds = require(DataSource.class); // work with data source }); } ``` -------------------------------- ### Install HeadHandler in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/handlers/head.adoc Install the HeadHandler to automatically route HEAD requests to GET handlers. The GET handler logic still runs, so consider custom implementations for expensive body generation. ```kotlin import io.jooby.handler.HeadHandler { use(HeadHandler()) // <1> get("/") { "Full response body" } } ``` -------------------------------- ### Install Vert.x SQL Client in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/templates/vertx-sql-client.adoc Install VertxModule, the SQL client module, and the Vertx handler. Then, retrieve the SQL client instance and execute a prepared query. ```java import io.jooby.vertx.VertxModule; import io.jooby.vertx.{{moduleName}}; import static io.jooby.vertx.VertxHandler.vertx; { install(new VertxModule()); <1> install(new {{moduleName}}()); <2> use(vertx()); <3> get("/{id}", ctx -> { var db = require(SqlClient.class); <4> return db.preparedQuery("SELECT id, name from World where id=$1") <5> .execute(Tuple.of(ctx.path("id").longValue())) .map(result -> { var row = result.iterator().next(); return new World(row.getInteger(0), row.getInteger(1)); }); }); } ``` -------------------------------- ### Quartz Integration (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/opentelemetry.adoc Install the OpenTelemetry module with the Quartz integration to track background task executions. Also install the Quartz module. ```java import io.jooby.quartz.QuartzModule; import io.jooby.opentelemetry.instrumentation.OtelQuartz; { install(new OtelModule(new OtelQuartz())); install(new QuartzModule(MyJobs.class)); } ``` -------------------------------- ### Install @trpc/client for Frontend Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/tRPC.adoc Install the official tRPC client library for your TypeScript frontend using npm. ```bash npm install @trpc/client ``` -------------------------------- ### Install Yasson Module Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/yasson.adoc Install the YassonModule to enable JSON-B support. This is the first step for JSON handling. ```java import io.jooby.json.YassonModule; { install(new YassonModule()); <1> get("/", ctx -> { MyObject myObject = ...; return myObject; <2> }); post("/", ctx -> { MyObject myObject = ctx.body(MyObject.class); <3> ... }); } ``` ```kt import io.jooby.json.YassonModule { install(YassonModule()) <1> get("/") { val myObject = ...; myObject <2> } post("/") { val myObject = ctx.body() <3> ... } } ``` -------------------------------- ### Install DbScheduler with SampleJob (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/db-scheduler.adoc Install the Hikari module and the DbScheduler module, providing recurring tasks. ```java import io.jooby.dbscheduler.DbSchedulerModule; { install(new HikariModule()); install(new DbSchedulerModule(Tasks.recurring(...))); } ``` -------------------------------- ### Install Thymeleaf Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/thymeleaf.adoc Install the Thymeleaf module and define a route that renders an index.html template with a 'name' attribute. ```kotlin import io.jooby.thymeleaf.ThymeleafModule { install(ThymeleafModule()) get("/") { MapModelAndView("index.html") .put("name", "Jooby") } } ``` -------------------------------- ### Install Jasypt Module in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/jasypt.adoc Install the Jasypt module to enable encrypted configuration properties. Ensure it's installed early in the application setup. ```kotlin import io.jooby.jasypt.JasyptModule { install(JasyptModule()) val property = config.getString("property") println(property) } ``` -------------------------------- ### Install Quartz Module and REST API Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/quartz.adoc Installs the Quartz module with a specified job class and exposes a REST API for scheduler management. ```java import io.jooby.quartz.QuartzApp; import io.jooby.quartz.QuartzModule; install(new QuartzModule(SampleJob.class)); use("/scheduler", new QuartzApp()); ``` -------------------------------- ### Install Jasypt Module in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/jasypt.adoc Install the Jasypt module to enable encrypted configuration properties. Ensure it's installed early in the application setup. ```java import io.jooby.jasypt.JasyptModule; { install(new JasyptModule()); String property = getConfig().getString("property"); System.out.println(property); } ``` -------------------------------- ### Lazy Initialization for `install` Operator (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/routing.adoc When using the `install` operator, child applications must be lazily initialized to ensure proper instantiation. ```java { install(() -> new Foo()); } ``` -------------------------------- ### Route Order Example (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/routing.adoc Demonstrates how routes are stacked and executed in the order they are defined, affecting the final output. ```kotlin { // Increment +1 use { val n = next.apply(ctx) as Int 1 + n } get("/1") { 1 } // Increment +1 use { val n = next.apply(ctx) as Int 1 + n } get("/2") { 2 } } ``` -------------------------------- ### Logback Integration (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/opentelemetry.adoc Install the OpenTelemetry module with the Logback appender to export application logs. Ensure the OpenTelemetry module is installed. ```java import io.jooby.opentelemetry.instrumentation.OtelLogback; { install(new OtelModule( new OtelLogback() )); } ``` -------------------------------- ### Route Order Example (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/routing.adoc Demonstrates how routes are stacked and executed in the order they are defined, affecting the final output. ```java { // Increment +1 use(next -> ctx -> { Number n = (Number) next.apply(ctx); return 1 + n.intValue(); }); get("/1", ctx -> 1); // Increment +1 use(next -> ctx -> { Number n = (Number) next.apply(ctx); return 1 + n.intValue(); }); get("/2", ctx -> 2); } ``` -------------------------------- ### Install Thymeleaf Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/thymeleaf.adoc Install the Thymeleaf module and define a route that renders an index.html template with a 'name' attribute. ```java import io.jooby.thymeleaf.ThymeleafModule; { install(new ThymeleafModule()); get("/", ctx -> { return new MapModelAndView("index.html") .put("name", "Jooby"); }); } ``` -------------------------------- ### Quartz Integration (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/opentelemetry.adoc Install the OpenTelemetry module with the Quartz integration to track background task executions. Also install the Quartz module. ```kotlin import io.jooby.quartz.QuartzModule import io.jooby.opentelemetry.instrumentation.OtelQuartz { install(OtelModule(OtelQuartz())) install(QuartzModule(MyJobs::class.java)) } ``` -------------------------------- ### Install Handlebars Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/handlebars.adoc Install the Handlebars module and define a route that renders an index.hbs template with a name variable. ```java import io.jooby.handlebars.HandlebarsModule; { install(new HandlebarsModule()); get("/", ctx -> { return new MapModelAndView("index.hbs") .put("name", "Jooby"); }); } ``` -------------------------------- ### Logback Integration (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/opentelemetry.adoc Install the OpenTelemetry module with the Logback appender to export application logs. Ensure the OpenTelemetry module is installed. ```kotlin import io.jooby.opentelemetry.instrumentation.OtelLogback { install(OtelModule( OtelLogback() )) } ``` -------------------------------- ### Install Vert.x SQL Client in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/templates/vertx-sql-client.adoc Install VertxModule, the SQL client module, and the Vertx handler. Then, retrieve the SQL client instance and execute a prepared query. ```kt import io.jooby.vertx.VertxModule import io.jooby.vertx.{{moduleName}} import static io.jooby.vertx.VertxHandler.vertx { install(VertxModule()) install({{moduleName}}()) use(vertx()) get("/{id}") { val db = require(SqlClient::class) <4> db.preparedQuery("SELECT id, name from World where id=$1") <5> .execute(Tuple.of(ctx.path("id").longValue())) .map({ result -> val row = result.iterator().next() World(row.getInteger(0), row.getInteger(1)) }) } } ``` -------------------------------- ### Get PBEStringEncryptor Instance in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/jasypt.adoc Retrieve the PBEStringEncryptor instance after installing the Jasypt module. This can be used for manual encryption/decryption if needed. ```kotlin import io.jooby.jasypt.JasyptModule { install(JasyptModule()) val encryptor = require(PBEStringEncryptor::class) } ``` -------------------------------- ### Get PBEStringEncryptor Instance in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/jasypt.adoc Retrieve the PBEStringEncryptor instance after installing the Jasypt module. This can be used for manual encryption/decryption if needed. ```java import io.jooby.jasypt.JasyptModule; { install(new JasyptModule()); PBEStringEncryptor encryptor = require(PBEStringEncryptor.class); } ``` -------------------------------- ### Install LangChain4j Module with Fallback Listener (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/langchain4j.adoc Install the LangChain4j module and attach a listener to monitor when failovers occur between configured models. ```java import io.jooby.langchain4j.LangChain4jModule; { install(new LangChain4jModule() ``` -------------------------------- ### Customize Validation Response in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/avaje-validator.adoc Customize the status code and title of the validation error response by configuring AvajeValidatorModule in Java. This example also installs AvajeJsonbModule. ```java { install(new AvajeJsonbModule()); install(new AvajeValidatorModule() .statusCode(StatusCode.BAD_REQUEST) .validationTitle("Incorrect input data") ); } ``` -------------------------------- ### Install and Configure Metrics Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/metrics.adoc Install the MetricsModule and configure various features like thread dumps, ping, health checks, and custom metrics. ```java { install(new MetricsModule() .threadDump() .ping() .healthCheck("deadlock", new ThreadDeadlockHealthCheck()) .metric("memory", new MemoryUsageGaugeSet()) .metric("threads", new ThreadStatesGaugeSet()) .metric("gc", new GarbageCollectorMetricSet()) .metric("fs", new FileDescriptorRatioGauge())); } ``` -------------------------------- ### Run Jooby App - Kotlin Source: https://github.com/jooby-project/jooby/blob/main/README.md Basic Kotlin example to run a Jooby application. Uses the runApp function for a concise setup. Ideal for Kotlin-based web projects. ```kotlin import io.jooby.runApp fun main(args: Array) { runApp(args) { get ("/") { "Welcome to Jooby!" } } } ``` -------------------------------- ### Configure Metrics Endpoints (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/metrics.adoc Install the MetricsModule and configure specific metrics to be exposed at the /sys/metrics endpoint. ```java { install(new MetricsModule() .metric("memory", new MemoryUsageGaugeSet()) .metric("threads", new ThreadStatesGaugeSet()) .metric("gc", new GarbageCollectorMetricSet()) .metric("fs", new FileDescriptorRatioGauge())); } ``` -------------------------------- ### Configure In-Memory Session Store with Custom Cookie Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/session.adoc Configures an in-memory session store using a custom cookie name. The example demonstrates setting and getting session attributes. ```java { setSessionStore(SessionStore.memory(new Cookie("SESSION"))); // <1> get("/", ctx -> { Session session = ctx.session(); session.put("foo", "bar"); return session.get("foo").value(); }); } ``` ```kotlin { sessionStore = SessionStore.memory(Cookie("SESSION")) // <1> get("/") { val session = ctx.session() session.put("foo", "bar") session.get("foo").value() } } ``` -------------------------------- ### Script Routes Example Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/openapi.adoc This example demonstrates how to document script routes using JavaDoc comments, including tags for version, server URL, and operation details. ```APIDOC ## GET /api/books ### Description Query and filter books. ### Method GET ### Endpoint /api/books ### Query Parameters - **query** (BookQuery) - Required - Book filter. ### Response #### Success Response (200) - **return** (List) - List of matching books. ## GET /api/books/{isbn} ### Description Find a book by ISBN. ### Method GET ### Endpoint /api/books/{isbn} ### Path Parameters - **isbn** (String) - Required - ISBN code. ### Response #### Success Response (200) - **return** (Book) - A book. #### Error Response (404) - **throws** (BookNotFoundException) - When a book doesn't exist. ``` -------------------------------- ### Basic MVC Controller and Application Setup (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/mvc-api.adoc Defines a simple MVC controller with a GET route and registers it in the Jooby application. The controller class is suffixed with an underscore by default. ```java import io.jooby.annotation.*; @Path("/mvc") // <1> public class Controller { @GET // <2> public String sayHi() { return "Hello Mvc!"; } } public class App extends Jooby { { mvc(new Controller_()); // <3> } public static void main(String[] args) { runApp(args, App::new); } } ``` -------------------------------- ### Install Quartz Module and REST API (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/quartz.adoc Installs the Quartz module with a specified job class and exposes a REST API for scheduler management using Kotlin. ```kt import io.jooby.quartz.QuartzApp; import io.jooby.quartz.QuartzModule; install(QuartzModule(SampleJob::class.java)) use("/scheduler", QuartzApp()) ``` -------------------------------- ### Install Jdbi and Hikari Modules Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/jdbi.adoc Install the Hikari and Jdbi modules to enable database connectivity and Jdbi integration. This sets up the DataSource and initializes Jdbi. ```java import io.jooby.hikari.HikariModule; import io.jooby.jdbi.JdbiModule; { install(new HikariModule()); install(new JdbiModule()); get("/", ctx -> { try (Handle handle = require(Handle.class)) { return handle.inTransaction(h -> { // Work inside transaction return result; }); } }); } ``` ```kt import io.jooby.hikari.HikariModule import io.jooby.jdbi.JdbiModule { install(HikariModule()) install(JdbiModule()) get("/jdbi") {ctx -> ctx.require(Handle::class).use { handle -> handle.inTransaction { // Work inside transaction result } } } } ``` -------------------------------- ### Lookup API Operation by GET Method Shorthand Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/openapi-ascii.adoc A shorthand for `operation("GET", path)` to retrieve a GET API operation. ```twig {{ GET("/books") }} ``` -------------------------------- ### Install Redis Module in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/redis.adoc Installs the Redis module and retrieves a Redis connection. Ensure the Redis module is installed before attempting to require a connection. ```kotlin import io.jooby.redis.RedisModule import io.lettuce.core.api.StatefulRedisConnection { install(RedisModule()) get("/") { val redis = require(StatefulRedisConnection::class) // work with Database } } ``` -------------------------------- ### Install Redis Module in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/redis.adoc Installs the Redis module and retrieves a Redis connection. Ensure the Redis module is installed before attempting to require a connection. ```java import io.jooby.redis.RedisModule; import io.lettuce.core.api.StatefulRedisConnection; { install(new RedisModule()); get("/", ctx -> { StatefulRedisConnection redis = require(StatefulRedisConnection.class); // work with redis }); } ``` -------------------------------- ### Install Vert.x SQL Client in Client Mode (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/templates/vertx-sql-client.adoc Install the SQL client module in client mode by passing a builder to the constructor. This is used for specific client configurations. ```java { ... install(new {{moduleName}}({{builderName}}::client)); ... } ``` -------------------------------- ### Install MCP Module and Inspector (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/mcp.adoc Installs the core MCP module and conditionally installs the McpInspectorModule in development environments. Ensure the inspector dependency is added. ```kotlin import io.jooby.mcp.McpModule import io.jooby.mcp.inspector.McpInspectorModule { install(McpModule( DefaultServiceMcp_(), CalculatorServiceMcp_() )) // Only enable the inspector UI in the 'dev' environment if (environment.isActive("dev")) { install(McpInspectorModule()) } } ``` -------------------------------- ### Build Project with Gradle Source: https://github.com/jooby-project/jooby/blob/main/modules/jooby-gradle-plugin/README.md After building the plugin with Maven, use this command to build the project. Ensure you replace `${project.version}` with the actual current version. ```bash ./gradlew build -PjoobyVersion=${project.version} ``` -------------------------------- ### Install MCP Module and Inspector (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/mcp.adoc Installs the core MCP module and conditionally installs the McpInspectorModule in development environments. Ensure the inspector dependency is added. ```java import io.jooby.mcp.McpModule; import io.jooby.mcp.inspector.McpInspectorModule; { install(new McpModule( new DefaultServiceMcp_(), new CalculatorServiceMcp_() )); // Only enable the inspector UI in the 'dev' environment if (getEnvironment().isActive("dev")) { install(new McpInspectorModule()); } } ``` -------------------------------- ### New Way to Boot Jooby Application Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/migration/4.x.adoc Illustrates the updated method for booting a Jooby application with explicit server and options configuration. This replaces older methods like `install(Server)` and `setServerOptions()`. ```java runApp(args, new NettyServer(new ServerOptions()), App::new); ``` -------------------------------- ### Install and Configure Metrics Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/metrics.adoc Install the MetricsModule and configure various features like thread dumps, ping, health checks, and custom metrics in Kotlin. ```kotlin { install(MetricsModule() .threadDump() .ping() .healthCheck("deadlock", ThreadDeadlockHealthCheck()) .metric("memory", MemoryUsageGaugeSet()) .metric("threads", ThreadStatesGaugeSet()) .metric("gc", GarbageCollectorMetricSet()) .metric("fs", FileDescriptorRatioGauge())) } ``` -------------------------------- ### Install Jackson and GraphQL Module (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/graphql.adoc Install the Jackson JSON library and the GraphQL module. The GraphQL module requires a RuntimeWiring to define data fetchers. ```java import io.jooby.json.Jackson2Module; import io.jooby.graphql.GraphQLModule; { install(new Jackson2Module()); <1> install(new GraphQLModule( RuntimeWiring.newRuntimeWiring() <2> .type(newTypeWiring("Query") .dataFetcher("bookById", fetchers.getBookByIdDataFetcher())) .type(newTypeWiring("Book") .dataFetcher("author", fetchers.getAuthorDataFetcher())) .build()) ); } ``` -------------------------------- ### URL Query Syntax Examples Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/value-api.adoc Demonstrates dot and bracket notation for accessing nested data in URL queries. ```text ?member.firstname=Pedro&member.lastname=Picapiedra ``` ```text ?member[firstname]=Pedro&member[lastname]=Picapiedra ``` ```text ?members[0]firstname=Pedro&members[0]lastname=Picapiedra ``` -------------------------------- ### Install Jooby MCP Modules with Jackson (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/mcp.adoc Install necessary modules for Jooby MCP integration using Jackson for JSON serialization. Ensure Jackson3Module, McpJackson3Module, and McpModule are installed. ```kt import io.jooby.jackson3.Jackson3Module import io.jooby.mcp.jackson3.McpJackson3Module import io.jooby.mcp.McpModule { install(Jackson3Module()) install(McpJackson3Module()) install(McpModule(CalculatorServiceMcp_())) <3> } ``` -------------------------------- ### Provide Custom Freemarker Configuration (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/freemarker.adoc Install the Freemarker module with a custom Freemarker Configuration object. ```kt import io.jooby.freemarker.FreemarkerModule { val freemarker = Configuration() install(FreemarkerModule(freemarker)) } ``` -------------------------------- ### Install Jooby MCP Modules with Jackson (Java) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/mcp.adoc Install necessary modules for Jooby MCP integration using Jackson for JSON serialization. Ensure Jackson3Module, McpJackson3Module, and McpModule are installed. ```java import io.jooby.jackson3.Jackson3Module; import io.jooby.mcp.jackson3.McpJackson3Module; import io.jooby.mcp.McpModule; { install(new Jackson3Module()); <1> install(new McpJackson3Module()); <2> install(new McpModule(new CalculatorServiceMcp_())); <3> } ``` -------------------------------- ### Install Avaje Validator Module with DI Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/avaje-validator.adoc Install the Avaje Validator module alongside a dependency injection framework like Avaje Inject. Ensure the DI framework is installed first. ```java import io.jooby.avaje.validator.AvajeValidatorModule; { install(AvajeInjectModule.of()); // <1> install(new AvajeValidatorModule()); } ``` -------------------------------- ### Install AvajeValidatorModule in Kotlin Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/avaje-validator.adoc Install the AvajeValidatorModule in your Jooby application using Kotlin. ```kotlin import io.jooby.avaje.validator.AvajeValidatorModule { install(AvajeValidatorModule()) } ``` -------------------------------- ### Install Jackson and GraphQL Module (Kotlin) Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/graphql.adoc Install the Jackson JSON library and the GraphQL module. The GraphQL module requires a RuntimeWiring to define data fetchers. ```kotlin import io.jooby.json.Jackson2Module import io.jooby.graphql.GraphQLModule { install(Jackson2Module()) <1> install(GraphQLModule( RuntimeWiring.newRuntimeWiring() <2> .type(newTypeWiring("Query") .dataFetcher("bookById", fetchers.getBookByIdDataFetcher())) .type(newTypeWiring("Book") .dataFetcher("author", fetchers.getAuthorDataFetcher())) .build()) ) } ``` -------------------------------- ### Install AvajeValidatorModule in Java Source: https://github.com/jooby-project/jooby/blob/main/docs/asciidoc/modules/avaje-validator.adoc Install the AvajeValidatorModule in your Jooby application using Java. ```java import io.jooby.avaje.validator.AvajeValidatorModule; { install(new AvajeValidatorModule()); } ```