perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Get all mapped routes #1100

Closed johnnybigoode-zz closed 3 years ago

johnnybigoode-zz commented 5 years ago

I want to implement #1006.

From what I understood, adding a httpRequest field to RouteMatchand exposing a getRoutes method in the Service and Sparkclasses.

A few lines were changed to accommodate the new field.

And a new test in MultipleServicesTest to check if everything is dandy.

perwendel commented 5 years ago

Thanks for commiting. I'll have a look next week.

perwendel commented 3 years ago

Reviewed and tested!! Thanks for contributing!

Paxa commented 12 months ago

May be it will be useful (with 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