Is there any way (like in a symfony application) to list down all the available/register routes on a vertx server? I am facing an issue that my registered route is returning a 404 on running restassure tests.
Yes, but you have to write a bit of code to achieve that.
// Example router setup
Router router = Router.router(vertx);
router.route(HttpMethod.GET, "/").handler(routingContext -> {
routingContext.response().end("Root");
});
router.route(HttpMethod.GET, "/users").handler(routingContext -> {
routingContext.response().end("Post");
});
router.route(HttpMethod.POST, "/users").handler(routingContext -> {
routingContext.response().end("Post");
});
// Getting the routes
for (Route r : router.getRoutes()) {
// Path is public, but methods are not. We change that
Field f = r.getClass().getDeclaredField("methods");
f.setAccessible(true);
Set<HttpMethod> methods = (Set<HttpMethod>) f.get(r);
System.out.println(methods.toString() + r.getPath());
}
This will result in:
[GET]/
[GET]/users
[POST]/users
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With