Skip to content

Instantly share code, notes, and snippets.

@passos

passos/.scala

Last active Jul 19, 2017
Embed
What would you like to do?
scala play WSRequest standalone script
/*
create `build.sbt` and add following content
```
scalaVersion := "2.11.1"
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.play" %% "play" % "2.5.12"
libraryDependencies += "com.typesafe.play" % "play-ws_2.11" % "2.5.12"
```
then, run `sbt console`, run following code
*/
import play.api.libs.ws._
import play.api.libs.ws.ahc.AhcWSClient
import akka.stream.ActorMaterializer
import akka.actor.ActorSystem
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val context = play.api.libs.concurrent.Execution.Implicits.defaultContext
val url = "https://mir-s3-cdn-cf.behance.net/project_modules/hd/0ec30954908977.596ea29c5ce53.png"
val ws = AhcWSClient()
val req = ws.url(url).get().map{
resp => println(resp.body.length)
}(system.dispatcher)
// after all futures completed...
ws.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment