-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathHttpClientExample.java
More file actions
30 lines (25 loc) · 961 Bytes
/
HttpClientExample.java
File metadata and controls
30 lines (25 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package io.vertx.example.virtualthreads;
import io.vertx.core.*;
import io.vertx.core.http.*;
public class HttpClientExample extends AbstractVerticle {
public static void main(String[] args) throws Exception {
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(HttpClientExample.class, new DeploymentOptions().setThreadingModel(ThreadingModel.VIRTUAL_THREAD))
.await();
}
@Override
public void start() {
var server = vertx.createHttpServer();
server.requestHandler(request -> {
request.response().end("Hello World");
});
server.listen(8080, "localhost").await();
// Make a simple HTTP request
var client = vertx.createHttpClient();
var req = client.request(HttpMethod.GET, 8080, "localhost", "/").await();
var resp = req.send().await();
var status = resp.statusCode();
var body = resp.body().await();
System.out.println("Got response status=" + status + " body='" + body + "'");
}
}