Skip to content

Instantly share code, notes, and snippets.

@passos
Last active July 19, 2017 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passos/46851f898c73efe71bfb82504cfe75ea to your computer and use it in GitHub Desktop.
Save passos/46851f898c73efe71bfb82504cfe75ea to your computer and use it in GitHub Desktop.
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