本文整理了Java中io.vertx.ext.web.Router.get
方法的一些代码示例,展示了Router.get
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.get
方法的具体详情如下:
包路径:io.vertx.ext.web.Router
类名称:Router
方法名:get
[英]Add a route that matches any HTTP GET request
[中]添加与任何HTTP GET请求匹配的路由
代码示例来源:origin: GoogleContainerTools/jib
@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());
}
});
}
代码示例来源:origin: vert-x3/vertx-examples
@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);
}
}
代码示例来源:origin: vert-x3/vertx-examples
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);
}
}
代码示例来源:origin: vert-x3/vertx-examples
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);
}
}
代码示例来源:origin: vert-x3/vertx-examples
@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);
}
}));
}
代码示例来源:origin: vert-x3/vertx-examples
@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);
}
}
代码示例来源:origin: vert-x3/vertx-examples
@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);
}
代码示例来源:origin: vert-x3/vertx-examples
@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);
}
}
代码示例来源:origin: vert-x3/vertx-examples
@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);
});
}
代码示例来源:origin: vert-x3/vertx-examples
router.get().handler(ctx -> {
代码示例来源:origin: vert-x3/vertx-examples
router.get().handler(ctx -> {
代码示例来源:origin: vert-x3/vertx-examples
router.get().handler(ctx -> {
代码示例来源:origin: vert-x3/vertx-examples
@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);
}
}
代码示例来源:origin: vert-x3/vertx-examples
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...");
代码示例来源:origin: vert-x3/vertx-examples
@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);
}
}
代码示例来源:origin: vert-x3/vertx-examples
router.get("/products/:productID").handler(that::handleGetProduct);
router.post("/products").handler(that::handleAddProduct);
router.get("/products").handler(that::handleListProducts);
代码示例来源:origin: vert-x3/vertx-examples
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 -> {
代码示例来源:origin: vert-x3/vertx-examples
router.get("/access-control-with-get").handler(ctx -> {
HttpServerResponse httpServerResponse = ctx.response();
httpServerResponse.setChunked(true);
代码示例来源:origin: vert-x3/vertx-examples
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!");
代码示例来源:origin: vert-x3/vertx-examples
router.get("/superAwesomeParameter")
.handler(HTTPRequestValidationHandler.create()
内容来源于网络,如有侵权,请联系作者删除!