Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example: Using Play Framework's WS library standalone
name := "WS Standalone Example"
version := "1.0"
scalaVersion := "2.11.5"
libraryDependencies ++= Seq(
"" %% "play-ws" % "2.4.0-M2"

This gist provides a simple example of how to use Play's WS library in a standalone application (external to Play).

build.sbt - SBT build file that includes the WS library WSStandaloneTest.scala - A simple example that utilizes WS to invoke an HTTP GET request

import com.ning.http.client.AsyncHttpClientConfig
// provide an execution context
object WSStandaloneTest {
def main(args: Array[String]) {
// set up the client
val config = new NingAsyncHttpClientConfigBuilder(DefaultWSClientConfig()).build
val builder = new AsyncHttpClientConfig.Builder(config)
val client = new NingWSClient(
// execute a GET request
val response = client.url("").get
// print the response body
response.foreach(r => {
// not the best place to close the client,
// but it ensures we dont close the threads before the response arrives
// Good enough for the gist :-D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment