play.api.libs.ws

WS

object WS

Asynchronous API to to query web services, as an http client.

Usage example:

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:

implicit val client = new NingWSClient(builder.build())
WS.url("http://example.com/feed").get()

Or call the client directly:

import com.typesafe.config.ConfigFactory
import play.api.libs.ws._
import play.api.libs.ws.ning._

val configuration = play.api.Configuration(ConfigFactory.parseString(
"""
  |ws.ssl.trustManager = ...
""".stripMargin))
val parser = new DefaultWSConfigParser(configuration, Play.current.classloader)
val builder = new NingAsyncHttpClientConfigBuilder(parser.parse())
val secureClient : WSClient = new NingWSClient(builder.build())
val response = secureClient.url("https://secure.com").get()

Note that the resolution of URL is done through the magnet pattern defined in WSRequestHolderMagnet.

The value returned is a Future[WSResponse], and you should use Play's asynchronous mechanisms to use this response.

Source
WS.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. WS
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. type Response = WSResponse

    Annotations
    @deprecated
    Deprecated

    (Since version 2.3.0) Please use play.api.libs.ws.WSResponse

  2. type WSRequest = ws.WSRequest

    Annotations
    @deprecated
    Deprecated

    (Since version 2.3.0) Please use play.api.libs.ws.WSRequest

  3. type WSRequestHolder = ws.WSRequestHolder

    Annotations
    @deprecated
    Deprecated

    (Since version 2.3.0) Please use play.api.libs.ws.WSRequestHolder

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def client(implicit app: Application): WSClient

    Retrieves or creates underlying HTTP client.

    Retrieves or creates underlying HTTP client. Note that due to the Plugin architecture, an implicit application must be in scope. Most of the time you will want the current app:

    import play.api.Play.current
    val client = WS.client
  8. def clientUrl(url: String)(implicit client: WSClient): ws.WSRequestHolder

    Prepares a new request using an implicit client.

    Prepares a new request using an implicit client. The client must be in scope and configured, i.e.

    implicit val sslClient = new play.api.libs.ws.ning.NingWSClient(sslBuilder.build())
    WS.clientUrl("http://example.com/feed")
    url

    the URL to request

    client

    the client to use to make the request.

  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  20. def toString(): String

    Definition Classes
    AnyRef → Any
  21. def url(magnet: WSRequestHolderMagnet): ws.WSRequestHolder

    Prepares a new request using a provided magnet.

    Prepares a new request using a provided magnet. This method gives you the ability to create your own URL implementations at the cost of some complexity.

    object PairMagnet {
      implicit def fromPair(pair: Pair[WSClient, java.net.URL]) =
        new WSRequestHolderMagnet {
          def apply(): WSRequestHolder = {
            val (client, netUrl) = pair
            client.url(netUrl.toString)
          }
       }
    }
    import scala.language.implicitConversions
    val client = WS.client
    val exampleURL = new java.net.URL("http://example.com")
    WS.url(client -> exampleURL).get()
    magnet

    a magnet pattern.

    See also

    The magnet pattern

  22. def url(url: String)(implicit app: Application): ws.WSRequestHolder

    Prepares a new request using an implicit application.

    Prepares a new request using an implicit application. This creates a default client, which you can then use to construct a request.

    import play.api.Play.current
    WS.url("http://localhost/").get()
    url

    the URL to request

    app

    the implicit application to use.

  23. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. def wsapi(implicit app: Application): WSAPI

    Attributes
    protected[play]

Inherited from AnyRef

Inherited from Any

Ungrouped