June 2018
Intermediate to advanced
310 pages
6h 32m
English
Notice that no matter which URL we specify, we always get the same result.
Of course, that's not what we want to achieve. Let's start by adding the most basic endpoint, which will only tell us that the service is up and running.
For that, we'll use Router:
val vertx = Vertx.vertx() // Was here beforeval router = Router.router(vertx)...
Router lets you specify handlers for different HTTP methods and URLs.
But, by default, it doesn't support coroutines. Let's fix that by creating an extension function:
fun Route.asyncHandler(fn : suspend (RoutingContext) -> Unit) { handler { ctx -> launch(ctx.vertx().dispatcher()) { try { fn(ctx) } catch(e: Exception) { ctx.fail(e) } } }}
If you are familiar with modern JavaScript, this is similar ...
Read now
Unlock full access