diff --git a/src/main/java/cavecomm/MainVerticle.java b/src/main/java/cavecomm/MainVerticle.java index e199f05..2a1446b 100644 --- a/src/main/java/cavecomm/MainVerticle.java +++ b/src/main/java/cavecomm/MainVerticle.java @@ -1,43 +1,72 @@ package cavecomm; import io.vertx.core.AbstractVerticle; +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; import io.vertx.core.MultiMap; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.Router; +import io.vertx.ext.web.RoutingContext; +import io.vertx.pgclient.PgConnectOptions; +import io.vertx.pgclient.PgPool; +import io.vertx.sqlclient.PoolOptions; +import io.vertx.sqlclient.Row; +import io.vertx.sqlclient.RowSet; +import io.vertx.sqlclient.SqlClient; public class MainVerticle extends AbstractVerticle { - @Override - public void start() throws Exception { - // Create a Router - Router router = Router.router(vertx); + @Override + public void start() throws Exception { + // Create a Router + Router router = Router.router(vertx); + // Mount the handler for all incoming requests at every path and HTTP method - // Mount the handler for all incoming requests at every path and HTTP method - router.route().handler(context -> { - // Get the address of the request - String address = context.request().connection().remoteAddress().toString(); - // Get the query parameter "name" - MultiMap queryParams = context.queryParams(); - String name = queryParams.contains("name") ? queryParams.get("name") : "unknown"; - // Write a json response - context.json( - new JsonObject() - .put("cavecomm", name) - .put("address", address) - .put("message", "Hello World") - ); - }); + Database db = new Database( + vertx, + 5432, + "localhost", + "testdb", + "testuser", + "123"); - // Create the HTTP server - vertx.createHttpServer() - // Handle every request using the router - .requestHandler(router) - // Start listening - .listen(8888) - // Print the port - .onSuccess(server -> - System.out.println( - "HTTP server started on port " + server.actualPort() - ) - ); - } - } \ No newline at end of file + //db.executeQuery("SELECT * FROM testtable"); + + router.get("/jsonTest").handler(rc -> { + db.executeQuery("SELECT * FROM testtable", rc); + } + ); + + + + + router.route().handler(context -> { + // Get the address of the request + String address = context.request().connection().remoteAddress().toString(); + // Get the query parameter "name" + MultiMap queryParams = context.queryParams(); + String name = queryParams.contains("name") ? queryParams.get("name") : "unknown"; + + + // Write a json response + context.json( + new JsonObject() + .put("cavecomm", name) + .put("address", address) + .put("message", "Hello World") + ); + }); + + // Create the HTTP server + vertx.createHttpServer() + // Handle every request using the router + .requestHandler(router) + // Start listening + .listen(8888) + // Print the port + .onSuccess(server -> + System.out.println( + "HTTP server started on port " + server.actualPort() + ) + ); + } +}