Best way to make a single Play Framework 2.6 action handle a route disregarding its HTTP method

We have a Play 2.6 Java application that works great so far.
Now we need to add some route to it that will just be taking the original request, decorating it with some additional headers or whatever and sending it forward to be handled by some other app (probably using Play’s WS client)
The question is if it is possible to create some route like this one in the Play routes file:

* /forward-to-smth/*whatever my.Action.forward

where * will match all the HTTP Methods, and we’ll be just getting the Http.Request instance in the action body and handling it as required.

What is the best way of handling this kind of scenarios in Play?
We can probably create multiple routes’ entries for each HTTP method and multiple actions in in the controller for each of the methods, delegating all the handling to a single handle-it-all method, but is there any more elegant solution?

Creating some custom HttpRequestHandler for this case will probably be an overkill?

I had the same issue, on my side the easiest solution was to create one route per method.
Using the RoutingDsl component I have:

.GET("/*to")
.routingAsync((request, to) ->
	webserviceProxyService.handleRequest(request)
)
.POST("/*to")
.routingAsync((request, to) ->
	webserviceProxyService.handleRequest(request)
)
.PUT("/*to")
.routingAsync((request, to) ->
	webserviceProxyService.handleRequest(request)
)
.PATCH("/*to")
.routingAsync((request, to) ->
	webserviceProxyService.handleRequest(request)
)
1 Like

thank you for your response, ended up handling it the same way :slight_smile: