5

In java spark web framework a route is defined as

get("/", (request, response) -> {
// Show something

});

In my application I define multiple routes. Is there any way I can get all the exposed routes of the application?

yellow boy
  • 149
  • 1
  • 7

2 Answers2

0

As far as I know, there's no way to automatically find REST routes as they do not have a standard registry service. Although, you can document them using Swagger or even store them using chrome applications such as Postman or Advanced Rest Client.

0

It's possible now in spark 2.9.4

import spark.Spark;
import spark.routematch.RouteMatch;

// somewhere after route definitions

for (RouteMatch route : routes()) {
    String method = route.getHttpMethod().toString();
    if (method.equals("before") || method.equals("after")) continue;
    System.out.printf("--> %-7s %s\n", method.toUpperCase(), route.getMatchUri());
}

output

--> POST    /internal/update_notification
--> GET     /internal/history
--> GET     /internal/history_details
--> GET     /ping
Pavel Evstigneev
  • 4,918
  • 31
  • 21