Dive into Vert.x
CCavalier
14.2K views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Be fluent In Vert.x
With vertex you can use a fluent API. It means multiple methods calls can be chained together. It make code a little bit less verbose.
Let's try to create de response to a request in plain text ("text/plain") who return "Hello world". Be careful: the header size must be definer or chunked. Don't forget to end your request !
One line it
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
31
package io.vertx.codingame;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.http.HttpServer;
/**
* Created by charlotte on 02/03/17.
*/
public class FluentServer extends AbstractVerticle {
/*
* Return a text with Hello World
*/
@Override
public void start(Future<Void> startFuture) throws Exception {
HttpServer server = vertx.createHttpServer();
server.requestHandler(req -> {
req.response().end("Ok");//complete here
});
server.listen(8080, ar -> {
startFuture.completer().handle(ar.map((Void)null));
});
}
}
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content