There's an example in the Play documentation for WS, under Using in a controller; I've adapted it to your scenario:
def showSomeSiteContent = Action.async {
WS.url("http://somesite.com").get().map { response =>
Ok(response.body)
}
}
The key thing to note is the idiomatic use of map()
on the Future
that you get back from the get
call - code inside this map
block will be executed once the Future
has completed successfully.
The Action.async
"wrapper" tells the Play framework that you'll be returning a Future[Response]
and that you want it to do the necessary waiting for things to happen, as explained in the Handling Asynchronous Results documentation.