Skip to content

Instantly share code, notes, and snippets.

@langley
Created February 24, 2013 19:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save langley/5025178 to your computer and use it in GitHub Desktop.
Save langley/5025178 to your computer and use it in GitHub Desktop.
A universal "Web Proxy Service" action for Play 2.1 Scala
# Add this to your conf/routes file
# Universal Proxy
GET /proxyGet/*urlToProxy controllers.Application.proxyGet(urlToProxy)
# Add this to a Controller class, e.g. Application
import play.api.libs.ws.WS
import play.api.libs.concurrent.Execution.Implicits._
def proxyGet(urlToProxy: String) = Action {
Async {
WS.url("http://" + urlToProxy).get().map { response =>
val contentType = response.header("Content-Type").getOrElse("text/plain")
Ok(response.body).as(contentType)
}
}
}
@langley
Copy link
Author

langley commented Dec 13, 2013

Note: this was for Play 2.1

@poornerd
Copy link

this is cool - I need to proxy POST as well. Can you point me to any examples?

@gdh56
Copy link

gdh56 commented Jul 14, 2014

Hey I am not sure if anyone is still looking but I based a class on this and it has all the requests https://github.com/gdh56/scalaPlayProxy/blob/master/proxy.scala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment