@Override public void start(Future<Void> startFuture) { Router router = Router.router(vertx); router.get("/").handler(this::hello); router.get("/time").handler(this::now); vertx.createHttpServer() .requestHandler(router) .listen(8080, asyncStart -> { if (asyncStart.succeeded()) { startFuture.complete(); logger.info("HTTP server running on port 8080"); } else { logger.error("Woops", asyncStart.cause()); startFuture.fail(asyncStart.cause()); } }); }
@Override public void start() { Router router = Router.router(vertx); router.get("/").handler(rc -> rc.response().end(UUID.randomUUID().toString())); vertx.createHttpServer() .requestHandler(router) .listen(8080); } }
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); router.get("/").handler(rc -> rc.response().end("Hello")); router.get("/:name").handler(rc -> rc.response().end("Hello " + rc.pathParam("name"))); vertx.createHttpServer() .requestHandler(router) .listen(8080); } }
public static void main(String[] args) { // Create the Vert.x instance Vertx vertx = Vertx.vertx(); // Create a router Router router = Router.router(vertx); router.get("/").handler(rc -> rc.response().end("Hello")); router.get("/:name").handler(rc -> rc.response().end("Hello " + rc.pathParam("name"))); // Start the HTTP server. vertx.createHttpServer() .requestHandler(router) .listen(8080); } }
@Override public void start() { Router router = Router.router(vertx); router.get("/").handler(this::invoke); // Retrieve the service discovery ServiceDiscovery.create(vertx, discovery -> // Retrieve a web client HttpEndpoint.getWebClient(discovery, svc -> svc.getName().equals("vertx-greeting"), ar -> { if (ar.failed()) { System.out.println("D'oh the service is not available"); } else { client = ar.result(); vertx.createHttpServer().requestHandler(router).listen(8080); } })); }
@Override public void start() throws Exception { // To simplify the development of the web components we use a Router to route all HTTP requests // to organize our code in a reusable way. final Router router = Router.router(vertx); // In order to use a template we first need to create an engine final JadeTemplateEngine engine = JadeTemplateEngine.create(vertx); // Entry point to the application, this will render a custom template. router.get().handler(ctx -> { // we define a hardcoded title for our application JsonObject data = new JsonObject() .put("name", "Vert.x Web"); // and now delegate to the engine to render it. engine.render(data, "templates/index.jade", res -> { if (res.succeeded()) { ctx.response().end(res.result()); } else { ctx.fail(res.cause()); } }); }); // start a HTTP web server on port 8080 vertx.createHttpServer().requestHandler(router).listen(8080); } }
@Override public void start() { setUpInitialData(); Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/products/:productID").handler(this::handleGetProduct); router.put("/products/:productID").handler(this::handleAddProduct); router.get("/products").handler(this::handleListProducts); vertx.createHttpServer().requestHandler(router).listen(8080); }
@Override public void start() throws Exception { // To simplify the development of the web components we use a Router to route all HTTP requests // to organize our code in a reusable way. final Router router = Router.router(vertx); // In order to use a Thymeleaf template we first need to create an engine final ThymeleafTemplateEngine engine = ThymeleafTemplateEngine.create(vertx); // Entry point to the application, this will render a custom JADE template. router.get().handler(ctx -> { // we define a hardcoded title for our application JsonObject data = new JsonObject() .put("welcome", "Hi there!"); // and now delegate to the engine to render it. engine.render(data, "templates/index.html", res -> { if (res.succeeded()) { ctx.response().end(res.result()); } else { ctx.fail(res.cause()); } }); }); // start a HTTP web server on port 8080 vertx.createHttpServer().requestHandler(router).listen(8080); } }
@Validate public void start() throws Exception { setUpInitialData(); TcclSwitch.executeWithTCCLSwitch(() -> { Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/products/:productID").handler(this::handleGetProduct); router.put("/products/:productID").handler(this::handleAddProduct); router.get("/products").handler(this::handleListProducts); router.get("/assets/*").handler(StaticHandler.create("assets", this.getClass().getClassLoader())); LOGGER.info("Creating HTTP server for vert.x web application"); HttpServer server = vertx.createHttpServer(); server.requestHandler(router).listen(8081); }); }
router.get().handler(ctx -> {
router.get().handler(ctx -> {
router.get().handler(ctx -> {
@Override public void start() { Router router = Router.router(vertx); router.get("/").handler(rc -> { String param = rc.request().getParam("name"); if (param == null) { param = "world"; } vertx.eventBus().<String>send("request", param, reply -> { if (reply.failed()) { rc.response().setStatusCode(400).end(reply.cause().getMessage()); } else { String content = reply.result().body(); rc.response().end(content); } }); }); vertx.createHttpServer() .requestHandler(router) .listen(8080); } }
router.get("/api/newToken").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end(jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(60))); router.get("/api/protected").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end("a secret you should keep for yourself...");
@Override public void start() throws Exception { final Image image = new Image(vertx, "coin.png"); Router router = Router.router(vertx); router.get("/").handler(ctx -> { ctx.response() .putHeader("Content-Type", "text/html") .end(image.generateHTML(16)); }); router.get("/img/:x/:y").handler(ctx -> { ctx.response() .putHeader("Content-Type", "image/png") .end(image.getPixel(Integer.parseInt(ctx.pathParam("x")), Integer.parseInt(ctx.pathParam("y")))); }); vertx.createHttpServer( new HttpServerOptions() .setSsl(true) .setUseAlpn(true) .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem"))).requestHandler(router) .listen(8443); } }
router.get("/api/newToken").handler(ctx -> { List<String> authorities = new ArrayList<>(); router.get("/api/protected").handler(ctx -> { }); router.get("/api/protected/defcon1").handler(ctx -> { }); router.get("/api/protected/defcon2").handler(ctx -> { }); router.get("/api/protected/defcon3").handler(ctx -> {
router.get("/access-control-with-get").handler(ctx -> { HttpServerResponse httpServerResponse = ctx.response(); httpServerResponse.setChunked(true);
router.get("/api/newToken").handler(ctx -> { router.get("/api/protected").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end("this secret is not defcon!"); router.get("/api/protected/defcon1").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end("this secret is defcon1!"); router.get("/api/protected/defcon2").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end("this secret is defcon2!"); router.get("/api/protected/defcon3").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end("this secret is defcon3!");
router.get("/superAwesomeParameter") .handler(HTTPRequestValidationHandler.create()