June 2018
Intermediate to advanced
310 pages
6h 32m
English
We'll leave the /alive endpoint as it is, but we'll extract all the other endpoints into a separate function:
private fun apiRouter(): Router { val router = Router.router(vertx) router.post("/cats").asyncHandler { ctx -> ctx.respond(status=501) } router.get("/cats").asyncHandler { ctx -> ... } router.get("/cats/:id").asyncHandler { ctx -> ... } return router}
There's a more fluent way to define it, but we left it that way as it is more readable.
Much as we supplied our main router to the Vert.x server instance, we now supply our subrouter to the main router as follows:
router.mountSubRouter("/api/v1", apiRouter())
Keeping our code clean and well separated is very important.
Read now
Unlock full access