This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Sample extends AbstractVerticle { | |
// Start method | |
@Override | |
public void start(Future<Void> startFuture) { | |
// Create a router object allowing to route HTTP request | |
final Router router = Router.router(vertx); | |
// Create a new get method listening on /hello resource with a parameter | |
router.route(HttpMethod.GET, "/hello/:name").handler(routingContext -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Router router = Router.router(vertx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.route(HttpMethod.GET, "/hello/:name").handler(routingContext -> { | |
// Retrieving request and response objects | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HttpServerRequest request = routingContext.request(); | |
HttpServerResponse response = routingContext.response(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String name = request.getParam("name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response.putHeader("Content-Type", "text/plain"); | |
response.setChunked(true); | |
response.write("Hello " + name); | |
response.setStatusCode(200); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response.end(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vertx.createHttpServer().requestHandler(router::accept).listen(8080, result -> { | |
if (result.succeeded()) { | |
startFuture.complete(); | |
} else { | |
startFuture.fail(result.cause()); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void start(Future<Void> startFuture) { | |
final Router router = Router.router(vertx); | |
// Create a BodyHandler to have the capability to retrieve the body | |
router.route().handler(BodyHandler.create()); | |
router.route(HttpMethod.POST, "/file").handler(routingContext -> { | |
HttpServerResponse response = routingContext.response(); | |
// Retrieve the body as a JsonObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JsonObject body = routingContext.getBodyAsJson(); | |
String filename = body.getString("filename"); |
OlderNewer