Last active
July 19, 2017 09:00
-
-
Save passos/46851f898c73efe71bfb82504cfe75ea to your computer and use it in GitHub Desktop.
scala play WSRequest standalone script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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