Closed johnnybigoode-zz closed 5 years ago
Wow. Great!
Just one thing to add - could the rersults return collection of RouteEntry objects which do contain HTTP method info:
In the Service.class
:
Collection<RouteEntry> routes();
If we map different HTTP methods to the same URL we could not set up the things correctly. Thank a lot!
If we map different HTTP methods to the same URL we could not set up the things correctly.
While I understand your concern and your use case, I'm not sure how to go from here. From what I checked from the code, all RouteMatch situations require to pass a HttpMethod
and it's not something I predicted.
Gonna reviews this and I'll get in touch.
So, from what I understood. The class
Spark
starts the whole thing, but you can create additionalSpark
s with the static methodspark.Service.ignite
Which literally gives us a
Service
object. The service class seems to have a field that holds all the routes called routes.Exposing that information would be the way to go.
In the Routes class, there are no methods for returning the whole route list, so that's where I started.
Using a similar structure to the method
findMultiple
in ln 124. I noticed that we could use the methodfindTargetsForRequestedRoute
to return all, but it depends onRounteEntry.matches
method that states:ln 47:
It was expected to have an option to return all. But it's not possible to find an httpMethod that returns ALL options. Maybe a better implementation would be creating a
SparkUtils.ALL_METHODS
and using something on those lines to create a better functionality.In our case, this is not necessary. If getting all routes means exposing the routes available to the dev, is it unthinkable to find reason to make this method internal. Since the only thing available to change routes seems to be
Routes.clear();
and it is only used byService.initiateStop()
, it's safe to say that routes are not mutable, so afindAll()
just needs to return a copy of all routes available to the running service.tldr:
I'm adding a
Routes.findAll()
method. Takes no arguments and returns a newList<RouteMatch>
with all that's available. Since there's not http method, path or accepted type to add to theRouteMatch
, I'm just adding all therouteEntry
information to the results.The
Routes
is used withinService
, so I added a findAll to Routes and afindAllRoutes
to Service and a staticfindAllRoutes
to Spark.New test for these features:
RoutesFindAllTest
.