Skip to content

Commit 5d84a42

Browse files
committed
build: example vertx standalone app
1 parent afd905b commit 5d84a42

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package examples.vertx;
7+
8+
import io.vertx.core.Vertx;
9+
import io.vertx.core.http.HttpServer;
10+
11+
public class VertxStandaloneApp {
12+
public static void main(String[] args) {
13+
// Create a Vert.x instance
14+
Vertx vertx = Vertx.vertx();
15+
16+
// Create the HTTP server
17+
HttpServer server = vertx.createHttpServer();
18+
19+
// Attach a single request handler for all incoming requests
20+
server.requestHandler(
21+
request -> {
22+
var response = request.response();
23+
response.putHeader("content-type", "text/plain");
24+
25+
// Check the request path to determine the response
26+
if (request.path().equals("/hello")) {
27+
response.end("Hello from Vert.x core!");
28+
} else if (request.path().equals("/about")) {
29+
response.end("This is a simple server using only vertx-core.");
30+
} else {
31+
response.setStatusCode(404);
32+
response.end("Not Found");
33+
}
34+
});
35+
36+
// Start the server and listen on port 8080
37+
server
38+
.listen(8080)
39+
.onSuccess(s -> System.out.println("HTTP server started on port " + s.actualPort()))
40+
.onFailure(t -> t.printStackTrace());
41+
}
42+
}

0 commit comments

Comments
 (0)