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.64k stars 1.56k forks source link

Q: Different routes, identical targets - possible? #947

Closed neilyoung closed 5 years ago

neilyoung commented 6 years ago

Hi, is it possible to have the same target handler being accessed using different routes?

E.g. get("/") should be handled like get("/index.html")

tipsy commented 6 years ago
Route myRoute = ...
get("/", myRoute);
get("/index.html", myRoute)

or

Class myClass {
    String myRoute(Request request, Response response) { ... }
}

get("/", myClass::myRoute);
get("/index.html",  myClass::myRoute)
ghost commented 6 years ago

I think a possible future feature would be an array or list of strings can be put into the first parameter of "get(...)" Or "post(...)". That would group up multiple routes to the same function.

On Wed, Nov 29, 2017, 12:36 PM David notifications@github.com wrote:

Route myRoute = ... get("/", myRoute); get("/index.html", myRoute)

or

Class myClass { String myRoute(Request request, Response response) { ... } }

get("/", myClass::myRoute); get("/index.html", myClass::myRoute)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/perwendel/spark/issues/947#issuecomment-347954069, or mute the thread https://github.com/notifications/unsubscribe-auth/AGtP5t1P8FHnd-rJb-MFc6Hc7nloCyLZks5s7aQUgaJpZM4QvXXs .

neilyoung commented 6 years ago

@codemon2002 : This is exactly the solution I would like and had actually in mind.

perwendel commented 5 years ago

I see no reason for this functionality. The provided example by @tipsy is a much clearer way of achieving this than pushing and array to the get,post,... functions