Inability to capture wildcards in Play Framework routes

I am browsing the HTTP API via Play, and to manage the changes related to the compatibility gap, the URL contains the version number. Currently, it looks like this:

GET /api/v1/someMethod com.foo.Api.someMethod() 

When I make changes to the output of one of the methods, I would like to support v2. However, for most methods, the behavior is identical, so I don't care which version is used. I tried to modify the above line as follows:

 GET /api/v:version/someMethod com.foo.Api.someMethod() 

But playback fails to compile with the error Missing parameter in call definition: version .

I know. I did not use the version parameter in the call because I did not need to! Is there any reasonable way to achieve what I will do here to make Play skip this check or put a wildcard on a route that was not written as a parameter?

(I suppose if I could not add a parameter to the method definition and then ignore it, but I would prefer to avoid this if possible.)

+6
source share
1 answer

After playing with this for a while, trying to find workarounds, I suspect that this may not be possible.

The big braking point is reverse routing. Play wants me to be able to use @routes.com.foo.Api.someMethod in my templates and allow the URL that this method will call. (And actually I do this in my API docs). If one of my above suggestions were accepted, it would be arbitrary what actual URL matches the method.

I assume that I really want the method to have a canonical URL, but for other similar patterns it was also considered a match. I agree that Play does not offer this as part of the syntax for simple file routes, and I would have to execute it myself (for example, using two patterns, ultimately a wildcard, but not directly referring to the same method).

+5
source

Source: https://habr.com/ru/post/958061/


All Articles