A WS proxy.
A file body
An in memory body
A streamed body
A streamed body
A flow of the bytes of the body
A streamed response containing a response header and a streamable body.
The base WS API trait.
A body for the request
The WSClient holds the configuration information needed to build a request, and provides a way to get a request holder.
WS client config
This class creates a DefaultWSClientConfig object from the play.api.Configuration.
This class creates a DefaultWSClientConfig object from the play.api.Configuration.
A WS Cookie.
A WS Cookie. This is a trait so that we are not tied to a specific client.
A WS proxy.
A WS Request builder.
WSRequestMagnet magnet.
WSRequestMagnet magnet. Please see the companion object for implicit definitions.
An HTTP response header (the body has not been retrieved yet)
Sign a WS call with OAuth.
Asynchronous API to to query web services, as an http client.
Asynchronous API to to query web services, as an http client.
Usage example:
class MyService @Inject() (ws: WSClient) { ws.url("http://example.com/feed").get() ws.url("http://example.com/item").post("content") }
When greater flexibility is needed, you can also create clients explicitly and pass them into WS:
import play.api.libs.ws._ import play.api.libs.ws.ahc._ import akka.stream.Materializer import play.api.ApplicationLifecycle import javax.inject.Inject import scala.concurrent.Future class MyService @Inject() (lifecycle: ApplicationLifecycle)(implicit mat: Materializer) { private val client = new AhcWSClient(new AhcConfigBuilder().build()) client.url("http://example.com/feed").get() lifecycle.addStopHook(() => // Make sure you close the client after use, otherwise you'll leak threads and connections client.close() Future.successful(()) } }
Or call the client directly:
import com.typesafe.config.ConfigFactory import play.api.libs.ws._ import play.api.libs.ws.ahc._ val configuration = play.api.Configuration(ConfigFactory.parseString( """ |play.ws.ssl.trustManager = ... """.stripMargin)) val parser = new DefaultWSConfigParser(configuration, app.classloader) val builder = new AhcConfigBuilder(parser.parse()) val secureClient: WSClient = new AhcWSClient(builder.build()) val response = secureClient.url("https://secure.com").get() secureClient.close() // must explicitly manage lifecycle
The value returned is a Future[WSResponse]
, and you should use Play's asynchronous mechanisms to
use this response.
(Since version 2.5.0) Inject WSClient into your component
An in memory body
The bytes of the body