gyokuro icon indicating copy to clipboard operation
gyokuro copied to clipboard

Support having default routes without a trailing slash in annotated controllers

Open fwgreen opened this issue 7 years ago • 3 comments

If one defines a partial path on the controller, the default route ends with a trailing slash:

route("/users")
controller class UserController {

    route("") //and route("/") both map to /users/
    shared void listUsers() {}
}

This might not conform to established conventions. Might an empty route, route("") or route, be treated as the default route and separate from route("/")?

route("/users")
controller class UserController {

    route //maps to /users
    shared void listUsers() {}

    route("/") //maps to /users/
    shared void somethingElse() {}
}

fwgreen avatar Aug 29 '16 23:08 fwgreen

I can also see the opposite: https://stackoverflow.com/questions/15196698/rest-resteasy-cutting-trailing-slash-off-path JAX-RS considers /users and /users/ to be the same routes.

I don't have a strong opinion on this topic, so if you have a real use for this feature I can implement it, it shouldn't be very hard.

bjansen avatar Sep 16 '16 17:09 bjansen

I see now that I was wrong in how I stated the problem; I assumed the behavior was by design. This might actually be a bug: Going by the JAX-RS behavior, both /users and /users/ should work, but currently that is not the case:

get("/users", (req, res) => "Hello");//Going to /users/ returns a 404 error

get("/users/", (req, res) => "Hello");//Going to /users returns a 405 error

fwgreen avatar Sep 16 '16 19:09 fwgreen

I would like to second this request, my expectation would be that either "", nothing, or null allows me to access the route without a trailing slash. Stripping off the last / as JAX-RS does would be fine too since it is superfluous anyways.

Fleshgrinder avatar Jan 22 '17 14:01 Fleshgrinder