1
votes

I'm slowly converting a REST API from Rails to Scala. I've got some methods working with play, but others have to fall back to the Rails server.

I want all requests to go through Play, but if they aren't implemented yet to redirect. Specifically if URL requested is play-app.com/api/v1/.* then it should be redirected to rails-app.com/api/v1/.*, with URL and all params in tact. I've tried this route:

GET /api/v1/*path

But now I don't know what to do with it.

1
Are you using some sort of frontend server? (By the way, that's the usual approach to running Play.) If so, handle the redirection via the frontend server. - Carsten
That was my first thought, but right now it's running on Heroku so I don't think that will work. - stevenheidel

1 Answers

3
votes

If your route is

GET   /api/v1/*path                  controllers.Api.v1(path: String)

Then your controller function would look something like this:

object Api extends Controller { request =>
    val queryString: String = if(request.rawQueryString.nonEmpty) "?" + request.rawQueryString else ""

    def v1(path: String) = Action {
         TemporaryRedirect("rails-app.com/api/v1/" + path + queryString )
    }
}